A
Al
I have a pass thru query from Access to SQL Server that
returns the results to an Excel spreadsheet. Everything
works fine but I would like to add the ability to autofit
the results into the columns in Excel when it opens with
the data. Below is a portion of the declarations and code
I'm using that works fine to open the spreadsheet; however
the autofit doesn't work. What am I doing wrong?
Dim strXLPath As String
Dim Sheet As Object, xlWrksht As Object
..
..
..
'Start Microsoft Excel and create a new Worksheet object.
strXLPath = "c:\Database\LIMS.xls"
Set xlWrksht = CreateObject("Excel.Sheet")
DoCmd.OutputTo acOutputQuery, "DateIDAnl", acFormatXLS,_
strXLPath, True
Set Sheet = xlWrksht.workbooks.Open(strXLPath).sheets(1)
'Make Excel visible
xlWrksht.Visible = True
xlWrksht.Columns("A:R").Select
xlWrksht.Columns("A:R").EntireColumn.AutoFit
Thanks in advance,
Al
returns the results to an Excel spreadsheet. Everything
works fine but I would like to add the ability to autofit
the results into the columns in Excel when it opens with
the data. Below is a portion of the declarations and code
I'm using that works fine to open the spreadsheet; however
the autofit doesn't work. What am I doing wrong?
Dim strXLPath As String
Dim Sheet As Object, xlWrksht As Object
..
..
..
'Start Microsoft Excel and create a new Worksheet object.
strXLPath = "c:\Database\LIMS.xls"
Set xlWrksht = CreateObject("Excel.Sheet")
DoCmd.OutputTo acOutputQuery, "DateIDAnl", acFormatXLS,_
strXLPath, True
Set Sheet = xlWrksht.workbooks.Open(strXLPath).sheets(1)
'Make Excel visible
xlWrksht.Visible = True
xlWrksht.Columns("A:R").Select
xlWrksht.Columns("A:R").EntireColumn.AutoFit
Thanks in advance,
Al