How to open a Workbook with a password, disable events,
and then copy a sheet in background to the second file and save.
I need in VBA, working in a MS-Access and Excel files
I have done this until now, is working.
Private Sub TestFunction()
'strPath = CurrentDb.Properties(0)
'strPath = Left(strPath, Len(strPath) - Len(Dir(strPath, vbNormal))) & "Temp\"
Dim CopyFrom As Object
Dim CopyTo As Object ''Early binding: Workbook
Dim CopyThis As Object
Dim xl As Object ''Early binding: New Excel.Application
Set xl = CreateObject("Excel.Application")
xl.Visible = True
Set CopyFrom = xl.Workbooks.Open("D:\A01.xls")
'CopyFrom.EnableEvents = False
Set CopyThis = CopyFrom.Sheets(1) ''Sheet number 1
Set CopyTo = xl.Workbooks.Open("D:\PM1.xls")
CopyThis.Copy After:=CopyTo.Sheets(CopyTo.Sheets.Count)
CopyFrom.Close
End Sub
This opens the Excel, I enter the pass copy’s the sheet to second File.
But I need to pass the password in background, delete the sheet and save the second file, all in background.
Also I need to delete a sheet, without asking me, like :
CopyTo.Sheets("Sheet1").Delete
Thank you
Password issue
Be careful to check wether it is an “open file” password (
passwordparameter) or a “modify file” password (WriteResPasswordparameter).Something like:
Delete without alert
For your second question, here is what you can do: