Err - Object Variable Or With Block Variable Not Set

So all you're trying to is set the font to bold a row in a spreadsheet?
 
Not sure how this fits into all of your other code but this works on my side:

Code:
Dim appexcel As Object
    Set appexcel = CreateObject("Excel.Application")
    appexcel.Workbooks.Open "book1.xls"
    appexcel.Visible = True
    appexcel.Sheets("Sheet1").Select
    appexcel.Rows("1").Font.Bold = True
 
Actually i'm ultimately trying to set the first row to bold and set the back color to light gray, and also set all of the columns to autofit.

i'm cutting corners to just try to get something (anything) to work so i can see where my problem lies, and add on from there.

Meanwhile, i've had a small success by taking out the .Workbooks property, and another error. The first section now works. The error now rests on the bolded line. i also need to add a Save Changes property somewhere, and the former code i had (SaveChanges:=True), which i borrowed from the internet, is not correct either.

Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
End With

objXL.Workbooks(strWkbkName).Close
objXL.Quit
Set objXL = Nothing

(Edited to remove the .Application the faulty line because it doesn't work either way.
 
Last edited:
To start with I'd take out the "With' stuff and the line continuations. Makes it eaiser to read / debug.
 
By George, i think i've got it! Now to apply it to the ACTUAL workbook that Access creates...
 

Users who are viewing this thread

Back
Top Bottom