C
Chutney via AccessMonster.com
I have a function in Access that I use to format my Excel spreadsheets but I
am having trouble with one line of code. The following works as a macro in
Excel:
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Font.Bold = True
End Sub
However, when I use the "Range(Selection, Selection.End(xlToRight)).Select"
in my Access code:
Dim appXL As Object
Set appXL = CreateObject("Excel.Application")
With appXL.Application
.Visible = False
.Workbooks.Open ("MyExcelFile")
.Range("A1").Select
.Range(Selection, Selection.End(xlToRight)).Select
.Selection.Font.Bold = True
End With
I get the error message: Error #91: Object variable or With block variable
not set
If I change ".Range(Selection, Selection.End(xlToRight)).Select" to ".Range
("A1:M1").Select" then the function works. However, I need to select the
column titles in row 1 dynamically because I do not know how many columns
there will be. Can anyone suggest what I need to make this work?
am having trouble with one line of code. The following works as a macro in
Excel:
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Font.Bold = True
End Sub
However, when I use the "Range(Selection, Selection.End(xlToRight)).Select"
in my Access code:
Dim appXL As Object
Set appXL = CreateObject("Excel.Application")
With appXL.Application
.Visible = False
.Workbooks.Open ("MyExcelFile")
.Range("A1").Select
.Range(Selection, Selection.End(xlToRight)).Select
.Selection.Font.Bold = True
End With
I get the error message: Error #91: Object variable or With block variable
not set
If I change ".Range(Selection, Selection.End(xlToRight)).Select" to ".Range
("A1:M1").Select" then the function works. However, I need to select the
column titles in row 1 dynamically because I do not know how many columns
there will be. Can anyone suggest what I need to make this work?