Opening workbook in invisible mode?

G

Gustaf

This code doesn't quite do what I want:

Set wbRemote = Workbooks.Open(temp, , True)

First, it opens the workbooks visibly, while I wish it to open in a hidden state. Second (probably due to the first), it changes the ActiveWorkbook. I also tried this

Set xlTmp = New Excel.Application
xlTmp.Workbooks.Open temp, , True

This works, but I it lacks in clarity. I like having a Workbook object to refer to, rather than the Excel.Application object, which I'm less familiar with. Any hints on how to get a Workbook object referring to an open (but invisible) workbook?

Gustaf
 
J

Jeff

Try somthing like this...

Private Sub Workbook_Open()
Dim xl As Object
Dim wrkBook As Object

Set xl = CreateObject("Excel.Application")
Set wrkBook = xl.Workbooks.Add

xl.Visible = False
With wrkBook.Worksheets(1)
.Cells(1, 1).Value = "Hello"
.Cells(1, 2).Value = "world"
End With

End Sub
 
B

Barb Reinhardt

First, you can define a workbook object.
dim myWB as excel.workbook

and replace this
xlTmp.Workbooks.Open temp, , True

with this
Set myWB = xlTmp.Workbooks.Open ( temp, , True )

Then you can use the workbook object. The application object works much the
same as the workbook object.

If you don't want to see what's happening on the screen during execution,
put this

XlTMP.Screenupdating = false (after you define it)

and reset to TRUE when execution is done

HTH,
Barb Reinhardt
 
J

Jim Cone

Set oWb = xlTmp.Workbooks.Open(temp)
--
Jim Cone
Portland, Oregon USA


"Gustaf" <[email protected]>
wrote in message

This code doesn't quite do what I want:

Set wbRemote = Workbooks.Open(temp, , True)

First, it opens the workbooks visibly, while I wish it to open in a hidden state. Second (probably due to the first), it changes the
ActiveWorkbook. I also tried this

Set xlTmp = New Excel.Application
xlTmp.Workbooks.Open temp, , True

This works, but I it lacks in clarity. I like having a Workbook object to refer to, rather than the Excel.Application object, which
I'm less familiar with. Any hints on how to get a Workbook object referring to an open (but invisible) workbook?

Gustaf
 
G

Gustaf

Gustaf said:
familiar with. Any hints on how to get a Workbook object referring to an
open (but invisible) workbook?

Many thanks for all the help on this.

Gustaf
 

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