Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Excel 2007 worksheets within Acess using VBA

Status
Not open for further replies.

commandchief

Programmer
Apr 29, 2004
12
US
I had the function below working in AccessXP but it no longer works in Access 2007. I get an error that says it can't create object. Any suggestions??

Function fixXLS(mySheetPath)

Set Xl = CreateObject("Excel.application")
Set Xlbook = GetObject(mySheetPath)

Xl.Visible = xlSheetHidden
Xlbook.Windows(1).Visible = True

Set Xlsheet = Xlbook.Worksheets(1)
Xlsheet.range("a1", "s600").AutoFormat
Xlsheet.range("a1", "s1").Font.Bold = True
Xlsheet.range("a2").Font.Bold = False
Xlsheet.range("a2").Font.Name = arial
Xlsheet.range("a2", "s400").EntireColumn.AutoFit
Xlbook.Save
Xlbook.Close
Xl.Quit
Set Xlbook = Nothing
Set Xlsheet = Nothing
Set Xl = Nothing

End Function
 
The workbook opens but nothing happens. I look back at my Access code and I see the error "Method 'Open' of object 'Workbooks' failed", run-time error -2147417851.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top