I've designed some vba coding to work from workbook1, this opens a workbook (call it workbook2), copy all of the data from the sheets in the workbook2 to the workbook1 and then close workbook2.
This code was working perfectly, until now! One of the worksheets that need to be opened have now been password protected, which I can't get access to due to the nature of the form, they've sent me the VBA coding in the forms, which is relatively generic.
Now the problem is when I try to run the code Workbooks(customerWorkbook.name).Close savechanges:=False I get the runtime error 1004 "application-defined or object-defined error", I'm 99% sure it's because the file is password protected as the non protected, macro free form they also sent me runs fine.
here is the code:
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
'run some code here
Application.DisplayAlerts = False
'Windows(customerWorkbook.name).Activate
'ActiveWindow.Close
Workbooks(customerWorkbook.name).Close savechanges:=False
Application.DisplayAlerts = True
As you can see I tried activating the sheet and closing it that way, but gives the same error message, my question is how can I force close a protected workbook without it throwing an error message??
The code works fine if I omit the close section of the code, but it's vital the workbook is actually closed and numerous ones will be opened - it's also strange that I can close the workbook without any problems by pressing the X close, or going to file-close on the workbook, just the VBA code isn't!
I've been banging my head at work for months to wrinkle out all of the problems, and now they've thrown this spanner into the works by password protecting it
Any help would be greatly appreciated!!
Thanks,
Omar!
Bookmarks