Is there a means to remove a KNOWN password from an Excel file via a VBA macro? Web searches only return the method to crack unknown Excel passwords.
I've automated all other aspects of the data handling except downloading files from an FTP site and subsequently removing the password.
You'll need to open the workbook specifying the passwords to open and modify, then saveas specifying an empty password for open and modify. To avoid getting prompts when overwriting the existing file, you need to disable alerts.
e.g.
Sub OpenAndSaveWithoutPasswords()
Dim wb As Workbook
Application.DisplayAlerts = False
Set wb = Workbooks.Open(Filename:="YOUR PATH AND FILENAME", Password:="OPEN PASSWORD", WriteResPassword:="MODIFY PASSWORD")
wb.SaveAs Filename:="YOUR PATH AND FILENAME AGAIN", Password:="", WriteResPassword:=""
Application.DisplayAlerts = True
End Sub
Note: Workbooks.Open seems to require brackets, wb.SaveAs requires no brackets (don't ask me why).
Just resave the workbook without a password:
ActiveWorkbook.SaveAs
Related
From MS Access, I open an Excel (.xlsx) file to apply some changes, save and upload it on Access. Everything is managed by VBA.
If the Excel file hasn't an open password encryption, VBA works perfectly.
In order to manage a Workbook encrypted with password, I have written a VBA that has many odd bugs. I give in the form the password as an input, but the password isn't read by the following code. Opening the Workbook, Excel asks me to insert the workbook password in the prompt. Then, Workbook.Unprotect doesn't unprotect the workbook that is saved with the password. As expected, Access cannot upload data from the protected Excel file.
I think should be a very easy problem to solve, but I cannot figure it out. Have you any insight to give me?
'( VBA procedure starts with variable declaration)
Set ExcelApp = CreateObject("Excel.Application")
If IsNull(Me!Password_Ins) 'Password_Ins is the input
Then
Strg_Pwd = ""
Else: Strg_Pwd = Me!Password_Ins
End If
On Error GoTo ErrorHandler
Set WorkBookObj= ExcelApp.Workbooks.Open(Percorso, False, , , Strg_Pwd) ' asks to insert the password manually
'ExcelApp.Visible = True
WorkBookObj.Unprotect Strg_Pwd 'doesn't remove the password
' (procedure continues)
WorkBookObj.Unprotect removes the worksheet password. It works well.
Strg_Pwd is the encryption password of the Excel file. Using as parameter of "Workbooks.Open" allows to open the file, but it is encrypted anyway. To avoid encryption, I created a new Excel file and copy&pasted the sheet.
So I have done some research but I can't get the feature I am looking for to work.
I am deploying a workbook to a lot of people on a network. I have an add-in on a network drive that all of the workbooks reference to. It works great when running the macros, no problem at all. My issue is updating the macros when people have one of the workbooks open. People leave things open for days sometimes, I know, cause I do the same thing sometimes.
I found this link, with the code below but I can't get it to work.
https://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment
The macro saves it as a .xlsm or a macro enabled workbook. It won't save it as a .xla
Sub DeployAddIn()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: To deploy finished/updated add-in to a network
' location as a read only file
Dim strAddinDevelopmentPath As String
Dim strAddinPublicPath As String
'Set development and public paths
strAddinDevelopmentPath = ThisWorkbook.Path & Application.PathSeparator
strAddinPublicPath = "F:\Addins" & Application.PathSeparator
'Turn off alert regarding overwriting existing files
Application.DisplayAlerts = False
'Save the add-in
With ThisWorkbook
'Save to ensure work is okay in case of a crash
.Save
'Save read only copy to the network (remove read only property
'save the file and reapply the read only status)
On Error Resume Next
SetAttr strAddinPublicPath & .Name, vbNormal
On Error Goto 0
.SaveCopyAs Filename:=strAddinPublicPath & .Name
SetAttr strAddinPublicPath & .Name, vbReadOnly
End With
'Resume alerts
Application.DisplayAlerts = True
End Sub
I've tried doing
.SaveAs FileFormat:=xlAddIn
Or
.`SaveAs FileFormat:=18`
Niether of those work. SaveCopyAs doesn't have a fileformat option.
Any suggestions or any other methods that might work?
You keep a copy of the XLAM on your local machine that you update, and then when you are ready to deploy it, you copy the XLAM to the server. Everyone else runs off a copy that is on the server (you dont want them to copy it to their local machine, btw) - The key is that when you copy it to the server, you have to set it to read-only in the file properties. You have to do that every time you copy it. Then you can overwrite it at any time.
Comment if you have any questions - I do this every day for work.
I'm working on a few VBA macros in Excel for a project. Is there a way to ensure that VBA macros don't launch from other Excel workbooks when you are opening them through a macro?
For example, let's say I have a macro inside one workbook to open some other Excel file:
Sheets("Sheet1").Select
PathName = Range("D3").Value
Filename = Range("D4").Value
TabName = Range("D5").Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=PathName &; Filename
What I've usually done is include a Application.EnableEvents = False to the subroutine to ensure that I'm not triggering code upon opening the other workbooks. This is also the methodology suggested by this prior SO post.
But two questions come to mind:
Is this "secure"? Are there other ways that users could write their own macros that execute on my active application even if I disable events?
Are there other workarounds besides fully disabling events? This seems somewhat limiting and almost "throwing the baby out with the bathwater".
This seems to open the file without the macros and it's read only.
When testing this, I can't even see the macro module in VBA editor for the opened file..
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Workbooks.Open Filename:=strFilepath & strFilename, ReadOnly:=True
Application.AutomationSecurity = msoAutomationSecurityByUI
I have an excel workbook that I download using simple HTML portal that I coded. When I download the workbook it automatically renames it as "myWorkbook (27)" or whatever number of times it has been put in the downloads folder.
I have some code that changes the Save As location of the workbook to the original location that it was downloaded from. See:
Private Sub Workbook_Open()
Application.DisplayAlerts = False
'Check to see if another workbook with the same name is open -- close if so.
If IsOpenWorkbook("myWorkbook.xlsm", True) Then
Workbooks("myWorkbook.xlsm").Close saveChanges = False
End If
ThisWorkbook.SaveAs Filename:="\\999.9.9.99\folder\anotherFolder\myWorkbook.xlsm"
Application.DisplayAlerts = True
End Sub
This has worked fine for almost a month but recently has been performing erratically. When I first download the sheet, it has the regular "Enable Editing" prompt which I accept. After accepting, the name of the workbook changes suggesting the code as run, but then has another "Enable Editing" prompt which, if I accept, will crash Excel.
Any insights appreciated.
The current active workbook is a macro-enabled one.
After performing some automated data manipulation, I want to save it as a new macro-free workbook (thus .xlsx instead of .xlsm). To do this, I recorded and edited a macro:
Dim newFilePath As string
newFileFullName = "C:\List.xlsx"
ActiveWorkbook.SaveAs Filename:=newFileFullName, FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
Workbooks.Open Filename:=newFileFullName
Windows("List.xlsx").Activate
However, whenever I run this macro, a window keeps popping up, asking for confirmation that I want to change the file format.
How can I suppress this pop-up and default it to "Yes"?
Add Application.DisplayAlerts = False
Thanks #simoco