Hello, I am using MSAccess and Excel 2003 for this example. I am attempting to open, modify and print an Excel document from within inside Access VBA. The open and print functions are working just fine. I cannot seem to figure out how to unprotect the sheet so I can modify a cells color. I do not wish to save the changes, just print and close. Any ideas, thank you. This is the code so far:
Dim appexcel As Object: Set appexcel = CreateObject("Excel.Application")
appexcel.Workbooks.Open Path & FilenameSheet
Worksheets("Sheet1").Unprotect "sherman"
Worksheets("Sheet1").Range("D312").Interior.ColorIndex = 41
Worksheets("Sheet1").Protect "sherman"
appexcel.Visible = False: appexcel.ActiveWindow.SelectedSheets.PrintOut Copies:=1
I get the error: Compile error. Sub or Function not defined with Worksheets highlighted.
Dim appexcel As Object: Set appexcel = CreateObject("Excel.Application")
appexcel.Workbooks.Open Path & FilenameSheet
Worksheets("Sheet1").Unprotect "sherman"
Worksheets("Sheet1").Range("D312").Interior.ColorIndex = 41
Worksheets("Sheet1").Protect "sherman"
appexcel.Visible = False: appexcel.ActiveWindow.SelectedSheets.PrintOut Copies:=1
I get the error: Compile error. Sub or Function not defined with Worksheets highlighted.