Opening an Excel Workbook

C

Crazyhorse

What is the difference?

I opened a excel work book this way and the Auto_Open function in excel will
not work?

Dim appexcel As Object
Dim StrFile As String
Dim MyPWD As String

StrFile = "\\infg\SLSmacros\MyStuff\DBs\Test_6\Output_template.xls"

Set appexcel = CreateObject("Excel.Application")
appexcel.workbooks.Open (StrFile)
appexcel.Visible = True

End Sub

If I creat a menu bar and put an assigned link (Hyperlink) excel workbook.
The Auto_Open function works great.

Why does it work one way and not the other way.


Thanks in advance
 
D

Dorian

"will not work"
what does this mean?
what happens?
Did you check the Excel object model?
Do you have the reference set?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
K

KC-Mass

Try Something like this (file name with path is passed in):

Sub FormatXLSheet(FileID As String)
Dim xlApp As Object
Dim wbExcel As Object
Dim ws As Worksheet
Dim lngRow As Long
Set xlApp = CreateObject("Excel.Application")
Set wbExcel = xlApp.Workbooks.Open(FileID)
'Do a bunch of cell Formatting Just left a few so you can check
ws.PageSetup.PrintTitleRows = "$1:$1"
ws.PageSetup.LeftFooter = "Printed &D"
ws.PageSetup.RightFooter = "Page &P of &N"
xlApp.Visible = True
xlApp.Workbooks(1).Close savechanges:=True
xlApp.Workbooks.Close
xlApp.Quit
Set xlApp = Nothing
End Sub

Regards

Kevin
 
K

KC-Mass

Sorry - edited out a needed line.


Sub FormatXLSheet(FileID As String)
Dim xlApp As Object
Dim wbExcel As Object
Dim ws As Worksheet
Dim lngRow As Long
Set xlApp = CreateObject("Excel.Application")
Set wbExcel = xlApp.Workbooks.Open(FileID)
'Do a bunch of cell Formatting Just left a few so you can check
' LEFT OUT KEY LINE
'--------------------------------
Set ws = wbExcel.Sheets(1)
'--------------------------------
ws.PageSetup.PrintTitleRows = "$1:$1"
ws.PageSetup.LeftFooter = "Printed &D"
ws.PageSetup.RightFooter = "Page &P of &N"
xlApp.Visible = True
xlApp.Workbooks(1).Close savechanges:=True
xlApp.Workbooks.Close
xlApp.Quit
Set xlApp = Nothing
End Sub
 

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