Saving a sheet as unhidden in VB

B

Barry Sommerfeld

I am writing an application in Visual Basic 6.0 that creates an Excel sheet
object, writes to it, and then saves the Excel file. When I load the file
in Excel, the workbook is hidden. I have to select Window->Unhide to unhide
it. Does anyone know how I can save the sheet as "unhidden?"

Thanks,
Barry Sommerfeld
(e-mail address removed)
 
E

eli silverman

There is a microsoft Knowledgebase article describing
this. I know because I saw it today but can't find it
anymore.
The basic gist of the article was that this occurs when
you use the getobject command and save it using the saveas
command. to correct this you must make the object visible.

if you want to use the getobject and saveas commands
consider the following

dim oexcel as object
dim osheet as object
set oexcel = getobject(filename.xls)
set osheet = oexcel.worksheets(1)
oexcel.parent.windows(oexcel.name).visible = true
oexcel.saveas newfilename.xls
oexcel.close

your alternative is to create a new workbook
dim oexcel as object
dim obook as object
dim osheet as object
set oexcel = createobject("Excel.application")
set obook = oexcel.workbooks.add
set osheet = obook.worksheets(1)
obook.saveas newfilename.xls
oexcel.quit
 
J

Johann de Jager

Barry I suggest you write a macro (in excel and the
workbook) that when you open the workbook it
outomatically unhides the workbook.
something like

Sheets("Sheet1").Visible = True
with the open workbook event

Johann
 
B

Barry Sommerfeld

That worked. Thanks.

Barry Sommerfeld


eli silverman said:
There is a microsoft Knowledgebase article describing
this. I know because I saw it today but can't find it
anymore.
The basic gist of the article was that this occurs when
you use the getobject command and save it using the saveas
command. to correct this you must make the object visible.

if you want to use the getobject and saveas commands
consider the following

dim oexcel as object
dim osheet as object
set oexcel = getobject(filename.xls)
set osheet = oexcel.worksheets(1)
oexcel.parent.windows(oexcel.name).visible = true
oexcel.saveas newfilename.xls
oexcel.close

your alternative is to create a new workbook
dim oexcel as object
dim obook as object
dim osheet as object
set oexcel = createobject("Excel.application")
set obook = oexcel.workbooks.add
set osheet = obook.worksheets(1)
obook.saveas newfilename.xls
oexcel.quit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top