PC Review


Reply
Thread Tools Rate Thread

Close Worksheet and Making Worksheet Invisible - Both fail

 
 
ekareem
Guest
Posts: n/a
 
      30th Dec 2009
Hi,
I use this (pardon the variable names...)

infile = "C:\Temp\Garb-Tests\Test1\solTrip.xlsx"
insheet = "Trip"
'---------------------------------------------------------------------
Set o = Workbooks.Open(infile).Worksheets(insheet)
....
Reading data from this works. However, this causes the sheet to open, but I
don't want that so I do:

o.Visible = false

When I do this, ths sheet still opens but it opens without any data!
Also, when I try to close this workbook using:

o.Close (false, false)

I get a runtime error 438 - Object does not support....

I also tried to close using this:

o.Close savechanges:=False

but that did not work either.

Any help for the close and the visible issues?

Thanks.

EK
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      30th Dec 2009
Hi


Your problem is that 'o' becomes a worksheet object, not as a workbook
object.

You can turn off screenupdating if you just need to read/write data and
close o again...

Sub test()
infile = "C:\Temp\Garb-Tests\Test1\solTrip.xlsx"
insheet = "Trip"
Dim o As Workbook
Dim sh As Worksheet
'---------------------------------------------------------------------
Application.ScreenUpdating = False
Set o = Workbooks.Open(infile) '.Worksheets(insheet)
Set sh = Worksheets(insheet)

'get data
o.Close False, False
Application.ScreenUpdating = True
End Sub


Hopes this helps.
....
Per

"ekareem" <(E-Mail Removed)> skrev i meddelelsen
news:0F9A3AD0-D44E-469D-B760-(E-Mail Removed)...
> Hi,
> I use this (pardon the variable names...)
>
> infile = "C:\Temp\Garb-Tests\Test1\solTrip.xlsx"
> insheet = "Trip"
> '---------------------------------------------------------------------
> Set o = Workbooks.Open(infile).Worksheets(insheet)
> ...
> Reading data from this works. However, this causes the sheet to open, but
> I
> don't want that so I do:
>
> o.Visible = false
>
> When I do this, ths sheet still opens but it opens without any data!
> Also, when I try to close this workbook using:
>
> o.Close (false, false)
>
> I get a runtime error 438 - Object does not support....
>
> I also tried to close using this:
>
> o.Close savechanges:=False
>
> but that did not work either.
>
> Any help for the close and the visible issues?
>
> Thanks.
>
> EK


 
Reply With Quote
 
ekareem
Guest
Posts: n/a
 
      30th Dec 2009
Hi Jessen,
Thanks for the tip.
You are correct. Following your point, Also,

o.Parent.Close

woked.

Thanks again



"Per Jessen" wrote:

> Hi
>
>
> Your problem is that 'o' becomes a worksheet object, not as a workbook
> object.
>
> You can turn off screenupdating if you just need to read/write data and
> close o again...
>
> Sub test()
> infile = "C:\Temp\Garb-Tests\Test1\solTrip.xlsx"
> insheet = "Trip"
> Dim o As Workbook
> Dim sh As Worksheet
> '---------------------------------------------------------------------
> Application.ScreenUpdating = False
> Set o = Workbooks.Open(infile) '.Worksheets(insheet)
> Set sh = Worksheets(insheet)
>
> 'get data
> o.Close False, False
> Application.ScreenUpdating = True
> End Sub
>
>
> Hopes this helps.
> ....
> Per
>
> "ekareem" <(E-Mail Removed)> skrev i meddelelsen
> news:0F9A3AD0-D44E-469D-B760-(E-Mail Removed)...
> > Hi,
> > I use this (pardon the variable names...)
> >
> > infile = "C:\Temp\Garb-Tests\Test1\solTrip.xlsx"
> > insheet = "Trip"
> > '---------------------------------------------------------------------
> > Set o = Workbooks.Open(infile).Worksheets(insheet)
> > ...
> > Reading data from this works. However, this causes the sheet to open, but
> > I
> > don't want that so I do:
> >
> > o.Visible = false
> >
> > When I do this, ths sheet still opens but it opens without any data!
> > Also, when I try to close this workbook using:
> >
> > o.Close (false, false)
> >
> > I get a runtime error 438 - Object does not support....
> >
> > I also tried to close using this:
> >
> > o.Close savechanges:=False
> >
> > but that did not work either.
> >
> > Any help for the close and the visible issues?
> >
> > Thanks.
> >
> > EK

>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new workbook and new worksheet and close. Worksheet not saved Patrick Microsoft Excel Programming 1 25th Jul 2009 07:00 PM
Create new workbook and new worksheet and close. Worksheet not sav Patrick Djo Microsoft Excel Programming 0 21st Jul 2009 02:19 PM
Create new workbook and new worksheet and close. Worksheet not sav Patrick Djo Microsoft Excel Worksheet Functions 0 20th Jul 2009 07:10 PM
Copy & paste cells fr open worksheet then close the worksheet =?Utf-8?B?U2lu?= Microsoft Excel Programming 1 2nd Oct 2006 02:20 PM
How to sum value from master worksheet taking value from other close worksheet nuha1578 Microsoft Excel Programming 1 3rd Nov 2003 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 PM.