I wrote a VB script that creates an .xls file, based on .xlt file. Then it calls a macro from the .xls file that populates it with information from a database. In the last step the script saves the .xls file on the disk.
I did this before with VB and Excel 2003. Now I upgraded to Excel 2007 and before it saves the file, a window pops up and tells me that:
"The following features can't be saved in macro free workbooks:
VB project
...some yada yada about what the Yes and No option do.
And the yes and no buttons in the dialog box.
"
I want the script to automatically select and execute Yes in the dialog box. But I can't figure how to do this. I've also posted the script I wrote.
If you have a better approach for this please share.
Thank you,
Steve
Sub Main()
Dim xl_app
Set xl_app = CreateObject("Excel.Application")
xl_app.Workbooks.Open("E:\Work\Send Mail\Clienti.xls")
'Run the macro
xl_app.Run( "ImportData(""Data Source=SFA;Initial Catalog=Campofrio;
Integrated Security=SSPI;Connect Timeout=3000"", -1, 47)")
xl_app.ActiveWorkbook.SaveAs FileName="E:\Work\Send
Mail\Clients.xls",FileFormat=xlNormal
xl_app.Quit
Set xl_app = Nothing
End Sub
Now the cod works but instead of saving the file at the specified location, it saves it in My Documents folder under FALSE.xls.
Merging responses from the two duplicate questions the poster asked:
1
Preventing False.xls when saving files in Excel
2
You are using named parameters in the .SaveAs wrong. When writing out the named parameter you'll have to do it in the format
FileName:="e:\myfile.xls"
Notice the colon before the equal sign.
If you just write Filename="myfile.xls" then its a boolean comparison that will return false. And thats why it save the file as false.xls.
Really funny error I think. ;)
I'm not sure if this is the problem, but shouldn't you just be saving as a .xlsm instead of .xls, which lets you save a macro-enabled workbook in Office 2007? You can check which version the macro is running on and if it's Excel 2007 then save as .xlsm, .xls otherwise...
Do you really need to save it with the macros included? If not, use:
ActiveWorkbook.SaveAs Filename:="E:\Work\Send Mail\Clients.xls", FileFormat:=xlNormal
EDIT: the key is that the extension used should match the FileFormat specified. The above works for me (to exclude macros) and the below works for me (to include macros). Neither has any popup, and both end up in the right directory (as the other poster mentioned, you have to have the := if you specify FileName; otherwise, use the form below.
ActiveWorkbook.SaveAs "c:\temp\wordmacros\mybook.xlsm", xlOpenXMLWorkbookMacroEnabled
Related
When linking workbooks in Excel, I often get an error like:
Links to xxxx.xlsx were not updated because xxxx.xlsx was not recalculated before it was last saved
This error pops up once for every linked value, which means in my case about 100 alerts I need to press OK for. Mysteriously, this alert comes even if xxxx.xlsx contains no formulas and hence no recalculation at all: it's completely full of values only.
So how does Excel know that a file has not been recalculated before saving? Is it looking at a particular xml value inside the ZIP file (xlsx) which I could tamper with? Is it looking at open date vs modified date that I could circumvent with the touch linux command? I'd like a solution Using the command line ubuntu if possible (I run windows WSL), so that I can use a script.
And what's more, xxxx.xlsx is really big, which over network (thanks COVID) at home is slow to open / recalc / save. So I really don't want to ever open this file in Excel.
Any ideas?
You could try adding this macro to your PERSONAL.XLSB file and then running it. It will ask you to select a file and then open it without allowing links to update.
Sub OpenWithoutUpdatingLinks()
Dim strFileName As String
strFileName = Application.GetOpenFilename
If strFileName <> "" Then Workbooks.Open FileName:=strFileName, UpdateLinks:=False
End Sub
This will allow you to open the file you're working on without getting the message about updating links.
However, if you actually need the links to update or need to create more links, then you need the linked file to be recalculated.
Let us know if you need instructions on adding a macro to your personal file and running it.
I have a module that I wrote in VBA with excel. This module formats an excel sheet and saves a new file at a specified destination. So far I've just been importing the module into the VBA project and running the script from there.
I have tried using powershell for this but it is not my strong suit and I have been running into security issues with excel.
Severally summarized module:
'Essentially a lot of standard excel formatting, sorting, and fill colors
'Prompts for save location
Dim Fldr As String
With Application.FileDialog(4)
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
Fldr = .SelectedItems(1)
End With
ActiveWorkbook.SaveAs Fldr & "\generated_report.xlsx", 51
Ideally I'd want an executable or script file that would prompt for the target excel file and then run the macro onto that file and save it in a destination, but all automatically.
The end-all be-all here would be a lightweight script file that could run without having to alter security settings within excel and could run on any machine with excel installed. Any help pointing me in the right direction for the method to use would be appreciated.
I ended up translating the VBA code into VBS, it opens the unformatted file and does operations onto it and then saves it as a new document. Works perfectly
Look into a VBA technique called Automation. One way you could solve the problem is with a .vbs script that Automates to each workbook file. You can run the .vbs script from the command line. E.g.:
https://www.experts-exchange.com/questions/23104413/Format-and-Excel-spreadsheet-using-vbscript.html
In Excel 2013: macro was working fine until today. Now, I can open the "Personal.xlsb" file, but I cannot use the Macro view button anymore, all I get is Excel in unresponding mode; and then, only way is to stop Excel entirely. When I go in design mode, I cannot access the macro registry at all (trying to do so results in the same unresponding state). I rebooted the PC entirely, did not help.
Pb seems specific to one specific "Personal.xlsb" file (I replaced the incriminated file with another "Personal" file in the XSTART folder and Excel macros worked just fine with a different .xlsb file). So I am suspecting a file corruption pb. If that is the case, is it possible to recover the original macros, or at least crack the macro file open and get a copy of the original coding?
You can try to get back your code if you manage to open the workbook from a macro in another workbook. Give this a shot:
create a folder where you will get the recovered code modules. Let's say "C:\myRecoveredCode". Put in a copy of your corrupt file "Personal.xlsb"
In Excel Options, Trust Center Settings, Check Trust Access to the VBA project object module
create a fresh workbook, copy/paste and run the following macro:
Sub TryRecovery()
myFolder = "C:\myRecoveredCode\"
Set wb = CreateObject(myFolder & "Personal.xlsb")
For Each comp In wb.VBProject.VBComponents
comp.Export myFolder & comp.Name
Next
wb.Close False
End Sub
If all goes well, you will have files a set of files that you can edit, or import to another workbook.
I am trying to isolate the issue causing
Excel 4.0 function stored in defined names.
Not to bump an old thread, but I had this same issue as well and wanted to post my resolution in case anyone else experiences the same thing as myself.
My problem ended up being caused by a MySQL Excel COM add-on that was a component included in the MySQL Workbench package. Disabling that add-on caused the macro prompt to disappear when saving spreadsheets.
For me this message was caused by the MySQL For Excel COM Add-In. The message stopped appearing when I unloaded the COM Add-In.
The solution already pointed out is correct: disable the MySQL for Excel COM Add-in.
The reason for the message is that this add-in adds hidden names to the workbook. These names are not visible in the Excel Names Manager. But you can see them in the VBA Direct Window if you add this code to a workbook module:
Public Sub DEV_CheckNames()
Dim n As name
For Each n In ActiveWorkbook.Names
If Not n.Visible Then
Debug.Print n.NameLocal, n.RefersToLocal
'If you want to delete the name, uncomment this line:
'n.Delete
End If
Next
End Sub
Result (for a German instance of Excel 2013):
LOCAL_DATE_SEPARATOR =INDEX(ARBEITSBEREICH.ZUORDNEN(37);17)
LOCAL_DAY_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);21)
LOCAL_HOUR_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);22)
LOCAL_MINUTE_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);23)
LOCAL_MONTH_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);20)
LOCAL_MYSQL_DATE_FORMAT =WIEDERHOLEN(LOCAL_YEAR_FORMAT;4)&LOCAL_DATE_SEPARATOR&WIEDERHOLEN(LOCAL_MONTH_FORMAT;2)&LOCAL_DATE_SEPARATOR&WIEDERHOLEN(LOCAL_DAY_FORMAT;2)&" "&WIEDERHOLEN(LOCAL_HOUR_FORMAT;2)&LOCAL_TIME_SEPARATOR&WIEDERHOLEN(LOCAL_MINUTE_FORMAT;2)&LOCAL_TIME_SEPARATOR&WIEDERHOLEN(LOCAL_SECOND_FORMAT;2)
LOCAL_SECOND_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);24)
LOCAL_TIME_SEPARATOR =INDEX(ARBEITSBEREICH.ZUORDNEN(37);18)
LOCAL_YEAR_FORMAT =INDEX(ARBEITSBEREICH.ZUORDNEN(37);19)
These names are added to the active workbook in the moment you click on the button of the add-in (which opens the taskpane). Unfortunately, I haven't found out yet why the MySQL add-in sometimes adds these names by itself without being activated.
Added: This is a known bug in the MySQL for Excel add-in as of http://bugs.mysql.com/bug.php?id=73467
I have the same problem in Excel 2013 and was solved by unloading the MySQL Add in - I did this by going to FILE - OPTIONS - Add Ins
I ran into this warning after creating the following defined name:
Name: wsNamesArray
Refers To: =RIGHT(GET.WORKBOOK(1),LEN(GET.WORKBOOK(1))-FIND("]",GET.WORKBOOK(1)))
This formula returns an array with names for each sheet in the workbook. I was using it to return the names of various sheets (first, last, previous and next sheet).
The problem is that this formula uses the GET.WORKBOOK Excel 4 function. From what I understand this is something like a VBA macro imbedded in a function. To save that functionality the Excel workbook must be saved in a format that allows macros such as .xlsm or .xlsb (or any of several other file types).
My choices were to delete the defined name containing an Excel 4 function or to replace the defined name with a formula without the Excel 4 function,
As in ChipsLetten's answer, same solution here on my computer: On saving some (actually macro free) workbook, I get an alert "Excel 4.0 function stored in defined names", and an option to save the workbook as "macro-enabled". On de-activating the "MySQL for Excel" COM-Add-in, the alert does not appear any more.
In order to disable the "MySQL for Excel" add-in (if you ever have installed it): Tab "Developper", then button "COM Add-Ins", and you get a list of add-ins that you can enable or disable per tick-mark.
have you installed some connector for excel?, maybe that's causing the issue, just uninstall it and the error will be gone.
If you have worksheets with hidden ranges as described in domke consulting's answer, you can use the following code to remove them:
Public Sub Remove_Hidden_MySQL_Names()
Dim n As Name
For Each n In ActiveWorkbook.Names
If Not n.Visible Then
'Delete Names added by MySQL for Excel add-in
If (InStr(n.NameLocal, "LOCAL_") <> 0 And (InStr(n.NameLocal, "_FORMAT") <> 0 Or _
InStr(n.NameLocal, "_SEPARATOR") <> 0)) Then
Debug.Print "Would delete", n.NameLocal, n.RefersToLocal
'If you want to delete the name, uncomment this line:
'n.Delete
Else
Debug.Print "Keeping", n.NameLocal, n.RefersToLocal
End If
End If
Next
End Sub
For me, in 2020, this issue is caused due to the fact that you want to save it into a .xlsx format. It needs to be saved in a .xls .xlsm or .xlsb file, which are macro enabled files. .xlsm is the preferred option.
I have a question on the macro events here. Below is my code. This performs the below Operations’
Private Sub SaveAsTabDelimited(ByVal sFileName As String)
With ActiveWorkbook
.SaveAs Filename:=sFileName, FileFormat:=xlText, CreateBackup:=True
End With
End Sub
Public Sub test()
SaveAsTabDelimited "C:\Users\te160772\Desktop\Toad Test\Testsanthu.txt"
ActiveWorkbook.Close savechanges:=True
End Sub
It converts the excel file into tab delimited txt file
It creates a backup copy of the excel file
I wanted this action to be performed each day inorder the excel file to upload to Oracle tables on daily basis. The reason behind converting excel spreadsheet to tab delimited txt file is to preserve the format (To prevent the removal of leading zeros while exporting it to oracle)
But now I am trying to enhance this code so that the following actions should be performed without any glitch. I have tried to do this in all the possible ways .since I am very new to the programming I was not able to do this.
The code should convert the excel file to tab delimited save on my desktop (Hope that my current piece of code is sufficient for this action)
It should create a backup copy in a folder called “Repository” (A folder in a desktop). Each change to my workbook should result a backup copy with the version history if possible(Date and Time stamp in the file name)
the biggest problem associated with my code is that upon close, three separate dialogue boxes appear - one asking me if i want to save, the other asking me if i want to keep what i have copied in the clipboard, another one is replace the existing text file saved in the folder is there a way of answering these dialogue boxes (or suppressing them) from within the macro, so i do not need to manually click on yes or no each time the macro is run?
I have attached my macro to a “shape” in excel but my priority is to run my macro upon closing of my workbook. Every time when any changes happen to my workbook and when I save the workbook, it should create a tab delimited Text files which should replace the existing Txt File without any confirmation dialogue boxes.
Please help me on this. This is badly require for me
With a million thanks
The code should convert the excel file to tab delimited save on my desktop (Hope that my current piece of code is sufficient for this action)
Yes, either you can hardcode the path to the desktop or use this code to get the path to the desktop automatically
Sub GetDesktopPath()
Dim oWS As Object
Dim DskTopPath As String
Set oWS = CreateObject("WScript.Shell")
DskTopPath = oWS.SpecialFolders("Desktop")
Debug.Print DskTopPath
Set oWS = Nothing
End Sub
It should create a backup copy in a folder called “Repository” (A folder in a desktop). Each change to my workbook should result a backup copy with the version history if possible(Date and Time stamp in the file name)
You can use the Workbook_BeforeSave event to create a copy of the existing workbook.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
End Sub
You may want to explore ThisWorkbook.SaveCopyAs See Excel Help for more info.
the biggest problem associated with my code is that upon close, three separate dialogue boxes appear - one asking me if i want to save, the other asking me if i want to keep what i have copied in the clipboard, another one is replace the existing text file saved in the folder is there a way of answering these dialogue boxes (or suppressing them) from within the macro, so i do not need to manually click on yes or no each time the macro is run?
You can get rid of these alerts by simply sandwiching your code between
Application.DisplayAlerts = False
'~~> Your Code
Application.DisplayAlerts = True
If you are using clipboard a lot, then you might also want to clear it by using
Application.CutCopyMode = False
I have attached my macro to a “shape” in excel but my priority is to run my macro upon closing of my workbook. Every time when any changes happen to my workbook and when I save the workbook, it should create a tab delimited Text files which should replace the existing Txt File without any confirmation dialogue boxes.
You can use the Workbook_BeforeClose event to run your relevant code
Private Sub Workbook_BeforeClose(Cancel As Boolean)
End Sub
Regarding the alert, I have already explained that in the previous section.
Hope this sets you in the right path.