L
LarryP
Need some help on code to do a simple manipulation (autofit the columns) in a
new Excel file I just created from Access. I had code already to set the
view to landscape, but I've gotten lost trying to add a couple additional
lines to do the autofit. Rows preceded by ### below are pre-existing code
that worked fine, other lines are my failed attempt to add the new thing. It
fails on the line preceded by @@@, saying the method is not supported. I
know it's very important when doing this to create and set the appropriate
objects, but I've tried it several ways and figure it's time to ask the gurus.
###Set oXL = CreateObject("Excel.Application")
###' Open newly generated Excel file
###Set oBook = oXL.Workbooks.Open(strOutputFile)
###Set oSheet = oBook.Sheets("qryDDMaster")
###oSheet.Activate
###oSheet.PageSetup.Orientation = xlLandscape
oSheet.Cells.Select
@@@oSheet.Selection.Columns.AutoFit
oSheet.Range("A1").Select
###'Save the Excel file
###oBook.Save
###' Close the Excel file
###' Then release any outstanding object references.
###oBook.Close (True)
###oXL.Quit
###Set oSheet = Nothing
###Set oBook = Nothing
###Set oXL = Nothing
new Excel file I just created from Access. I had code already to set the
view to landscape, but I've gotten lost trying to add a couple additional
lines to do the autofit. Rows preceded by ### below are pre-existing code
that worked fine, other lines are my failed attempt to add the new thing. It
fails on the line preceded by @@@, saying the method is not supported. I
know it's very important when doing this to create and set the appropriate
objects, but I've tried it several ways and figure it's time to ask the gurus.
###Set oXL = CreateObject("Excel.Application")
###' Open newly generated Excel file
###Set oBook = oXL.Workbooks.Open(strOutputFile)
###Set oSheet = oBook.Sheets("qryDDMaster")
###oSheet.Activate
###oSheet.PageSetup.Orientation = xlLandscape
oSheet.Cells.Select
@@@oSheet.Selection.Columns.AutoFit
oSheet.Range("A1").Select
###'Save the Excel file
###oBook.Save
###' Close the Excel file
###' Then release any outstanding object references.
###oBook.Close (True)
###oXL.Quit
###Set oSheet = Nothing
###Set oBook = Nothing
###Set oXL = Nothing