am getting the above error message in some VBA code. Here is the line of code where I am getting the error message.
Set xlSheet = CreateObject("Excel.Worksheet")
This code is within an Access database and I am trying to create Excel spreadsheet files. I am new to VBA so I'm kinda brain dead...please bare with me. I have also attached the function that has this line of code as well.
Thanks for your help in advance.Code:Function formatXLFiles(userChoice As Boolean) Dim xlApp, xlSheet, myXLWrkBook As Object Dim databasePath Dim XLMacroPath databasePath = ExtractPath(CurrentDb.Name) XLMacroPath = databasePath & "\FormatFieldReports.xls" 'Open connection to Excel Workbook and make it visible Set xlApp = CreateObject("Excel.Application") Set myXLWrkBook = GetObject(XLMacroPath) myXLWrkBook.Application.Visible = True myXLWrkBook.Application.Windows(1).Visible = True Set xlSheet = CreateObject("Excel.Worksheet") xlApp.Application.Workbooks.Open XLMacroPath xlApp.xlSheet.Columns.autofit = True 'Run procedure in ThisWorkBook folder If userChoice Then myXLWrkBook.Application.Run "ThisWorkbook.openForProcessing(true)" Else myXLWrkBook.Application.Run "ThisWorkbook.openForProcessing(false)" End If 'Close Automation object 'Either invoke the save method or set the Saved property to true to avoid a prompt about saving changes 'myXLWrkBook.Application.ActiveWorkbook.Save myXLWrkBook.Application.ActiveWorkbook.Saved = True myXLWrkBook.Application.ActiveWorkbook.Close Set myXLWrkBook = Nothing xlApp.Quit Set xlApp = Nothing End Function
Blake




Reply With Quote