Save a newly generated excel file in VB script - vbscript

My VB code generates a Excel file.
I need to save this excel file at specific location.
Can you please share how can I do that.
Any pointer will be appreciated.

Try
ActiveWorkbook.SaveAs Filename:="your_filename_here.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

Related

A question about Power Automate to proceed macro from another excel file

Hello I am a newbie that working on a project that requires to use Power automate desktop to analyze data in the excel worksheet. The project needs me to download a excel file from website and proceed with macro. Now I am able to download file from website and macro script has been tested without problem. So here comes the problem, I couldn't figure out how to use power automate to run macro from another excel file.
So let's say there are two excel file a.xlsm and b.xlsm and both store in download folder. The a.xlsm will always been the download file from website and b.xlsm will be the file that I already store the macro. I need to open a.xlsm and run the macro store in b.xlsm. Thanks for any suggestion in advance.
Ok I figure it out, here is the step you may follow.
Record Macro
Stop recording the Macro
Click Macros under developer section (or press Alt + F11)
Find the Module 1 under VBAProject (PERSONAL.XLSB (Default name))
Copy your finished script and paste into the module1
In the run excel macro function in Power Automate Desktop, put that code after Macro: 'PERSONAL.XLSB'!**** (**** will be the macro function you want to run)
note: please remember every time you want to run the macro you have to open the original worksheet which contains the macro, otherwise you won't be able to run it

Windows 7: Right click on file and run custom Excel VBA script

I wrote a macro in Excel VBA that can scrape files with an .f06 extension for certain data and then creates a spreadsheet that summarizes the data.
It is inconvenient to have to find the Excel workbook, open it, run the macro, & select the .f06 file to generate this summary.
I prefer to right-click on the .f06 file directly and have an option called 'scrape' that I could select and then it would run the code automatically.
1) Is this possible?
2) Can I use the existing macro-enabled Excel spreadsheet as the referenced code? Or do I need to re-write it in another language?
I am using Windows 7 Enterprise SP1 if relevant.
Thank you.
This is possible, but if you're on a company computer, I doubt that you'll be able to do some of the required steps.
1) write a VBScript for your macro according to the following guide:
http://wellsr.com/vba/2015/excel/run-macro-without-opening-excel-using-vbscript/
2) Launch the VBS you wrote in Step 1 from the right click menu, according to the following guide:
http://www.visualbasicscript.com/Launch-vbs-from-the-rightclick-menu-advanced-m32062.aspx
Best of luck!

Write to New File Created By Notepad In Lua

I'm aiming to open a new .txt file in Notepad and then write to it. Since the file I'm opening (notepad.exe) isn't the same file I want to write to (the new .txt file), I'm unaware of how I can write to the file. Here's the code I have so far:
local list = io.popen("notepad.exe","w")
print(list)
list:write("Tester")
list:flush()
Notepad is opened, but the text isn't written to the new file because the code is trying to edit notepad.exe instead.
What can I do to be able to edit the new opened .txt file? I don't want to actually save the file anywhere, so that's why I'm aiming to just put text in an untitled .txt file. Thanks in advance :)
Notepad does not respond console input.
You must find edit control on notepad's window and PostMessage keypressing event to it.
Or prepare temporary file and load it:
local list = io.open("newfile.txt","w")
list:write("Tester")
list:close()
os.execute("notepad.exe newfile.txt")

Exception with Excel SaveCopyAs() method

I have generated a excel report using excel-addins in vs2010 and it saved to desktop. After that I reopened the same file and changed it's data. When I tried to save back with same file name Exception occurs.
Code:-
Globals.ThisAddIn.Application.ActiveWorkbook.SaveCopyAs(saveFileDialog1.FileName);*
Exception:-
System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot access the file 'C:\Documents and Settings\112\Desktop\111.xlsx'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Check to see that your file isn't being used by something else.
You are almost certainly hitting a file access exception, probably because the document you are attempting to write is already open in another program.
I'm guessing that program is Microsoft Excel.
Close the document in Excel and re-run your test.

How do I launch an Excel document in Windows, edit it and get the application to ask to save it?

I can launch Excel with the document I want using VB.Net 2010:
Dim p As New System.Diagnostics.Process
p.StartInfo.FileName = "c:\temp\myfile.xlsx"
p.Start()
Excel starts OK with the file opened. I edit the file, but when I close it down, Excel doesn't ask if I want to save changes. So it closes and loses my edits.
If I do the same with a text file:
Dim p As New System.Diagnostics.Process
p.StartInfo.FileName = "c:\temp\myfile.txt"
p.Start()
It opens (in Notepad++), I edit it and close it, and Notepad++ asks if I want to save changes. Great!
I've now tried similar code with a Word document - and that's OK. Also with an OpenOffice Sheet document and that works as well.
This behaviour is happening in Windows 7 with Excel 2010. It works as expected in Windows XP with Excel 2007.
What am I doing wrong with Excel? Is it me?
I couldn't recreate your error. I ran the app with and without Excel already being open. I closed out of Excel and then by just closing the workbook only. I was prompted to save each time.
You may need to check your settings in Excel. Could be a security setting. Are you doing any other changes to the excel file programatically or are they just manual changes through the Excel UI only?
Maybe SuperUser.com can help.
OK, so it's not related to the way I was opening the document (using System.Diagnosis.Process). I initially thought it was. If I open files via Explorer, edit them and close Excel, it doesn't ask to save the changed file. So it's not a programming issue.
Thanks for the help anyway guys.
Dave

Resources