I am trying to run a small VBS script to open an Excel workbook, but every time I run my script, Excel will only load as a background application (confirmed in Task Manager) but will not display. I feel like I am missing something very silly, but I have browsed form after form talking about VBS scripts launching Excel, and I can't seem to get any of them to work. Any input you might have would be greatly appreciated, thanks :)
Option Explicit
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("FilePath", 0, True)
Application.Caption = "OnMax"
*Note I replaced the actual file path with just Filepath to make sure it fit and one line and no one had to scroll, but incase it matters the file path is: M:\Projects\Onmax II\Documents\R&D\Standalone App\VB Script Test\Test.xlsm
The script is doing exactly what you asked it to do it started an instance of Excel.
You just didn't tell it yet to make the application visible.
Adding the following code should help
xlApp.Visible = true
Related
So I have an excel file, which is basically a table.
I have another excel file with a VBA script which is used as a converter for that Excel file to search for specific entries and output them in text.
I've been trying to automate it, but I can't come up with a solution.
This is what the original Excel looks like:
This is how the "converter" looks like
It works like: We open it, click the button, windows pops up, we select the file which has always the same path, and the name of the file is always tomorrows date. It then places the "converted" file into path that has been saved before.
This is what the "converted" version looks like:
So as I mentioned before, I'm looking to automate this step, as this is one of the many mundane tasks that is needed to be performed on daily basis.
I was wondering what my options are.
Maybe it is possible to make the input file get selected automatically?
Or maybe there is a way in which I can extract the VBA script from excel and automate it using Powershell, in which I can set the filenames to be tommorows dates.
Any help is greatly appreciated.
We tried contacting the contractor who made the converter scripts, but we can't reach him anymore.
You can make a vbscript (*.vbs) and run it through opening it or Task Scheduling;
In the script below (which you can simply copy/paste into note pad and save as "Converter.vbs"), you need to change the path to "Converter" workbook, change the name of the macro that does the job.
I would apply a change to your macro too; Instead of an input for name and path, use explicit coding that path is hard-coded in it and get the name based on the system's date. This way there's no need for user interaction with the script.
Option Explicit
'On Error Resume Next ''Comment-out for debugging
ExcelMacro
Sub ExcelMacro()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\path\to\Converter.xlsm", 0, True)
xlApp.Run "Convert" 'This line runs your macro (called Convert)
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
This might sound confusing, and I'm not entirely sure it's possible to do it the way I want, but what I'm looking to do is create a script that will take a .txt file and run Excel macros on it, without actually opening up Excel or the file. One of the blogs I was reading suggested this method, but I'm not very familiar with VBS.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'Path\Test.xlsm'!Module.Macro"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
This did not work when I tried to use it with a .txt file.
The error I receive is Cannot run the macro Path.... The macro may not be available in this workbook or all macros may be disabled
I'm sure it has something to do with my lack of VBS knowledge, but so far it's been the closest kind of script I've found for what I'm looking for. Is what I'm trying to do possible?
You need to open the workbook before you can run macros from it.
...
Set wb = objExcel.Workbooks.Open("C:\path\to\Test.xlsm")
objExcel.Application.Run "'Path\Test.xlsm'!Module.Macro"
...
You can't run a macro without opening Excel or the file containing the macro. If you want something like that you need to translate the VBA code to plain VBScript.
Path statement need full path eg " c:\ .... "
And I think it should be Module1.Macro_Name (not Module)
Write in note pad but save with .vbs on desktop. Just click on the run
I am trying to schedule a vba script. I am working through the company server and am wondering if I can not access this due to administrative restrictions? here is the code:
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\\Computer\denfs1\data\1EpUSRgltry\Permitting - Wells & Sundries\WEST (CO-MT-ND)\Schedules & Status\Planning and Permiting Spread sheet(West) Permit and Planning spread sheet.xlsm", 0, True)
xlApp.Run "Click"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
Here is the error I am getting
What does the macro "Click" do? If it make changes, close it without saving (change to True if you want to save changes by the Click macro).
xlBook.Close False
You may also want to debug from Excel by putting xlApp.Visible = True before opening the .xlsm workbook.
There might be a hidden Excel.exe locking that same file from previous script execution (say you press Ctrl-C before the macro "Click" finishes). Close all visible Excel windows and ensure there are no Excel.exe running in task manager.
If you keep pressing Cancel when Excel asks you to save changes to it, it will stuck in background even the vbs did not pick up any error.
The problem was a syntax error with the name of the file... Make sure you have the whole string accurate :/
I know there are other posts similar to this but I cannot seem to get this to work. I just want to create a .vbs file to use with the scheduler to kick off a macro in Excel on monthly basis. Here is what I have been trying:
Option Explicit
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Test\TEST.xlsm", 0, True)
xlApp.Run "Macro1"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Quit
I just get a warning message every time saying that TEST.xlsm already exists and do I want to overwrite it. When I click Yes, the changes never take effect.
I don't want to get any message at all, and I don't know why the changes from the macro are not occurring.
I've tried to use
xlApp.SaveAs
and I cannot get that to work either. Plus the workbook appears to not be closing correctly.
Thanks in advance, I am new to this so maybe I am just missing something stupid.
I am relatively new to the true power in Excel - Macros/VBA and have been tasked to set up the financial model for a million dollar project. I am able to set everything up and have it run smoothly, but there's too much manual input involved. I would like to seek simplification through the power of VBA.
This is my dilemma:
I need to be able to individually double-click on a specific set of cells (in a Row), which will open up a file window that allows me to select a EXL file.
Once I select the file, that file should be preferably opened in a temp status (not visible, but I can run functions and pull info from it).
I will then need the macro to go into that opened sheet, conduct a simple SUMIFS function, and record the outcome in a column of the current sheet I'm working from.
I've been doing some Excel tutorial on Lynda in hope to seek the answers there, but I think the complexity of this request demands the knowledge of a true master.
Any help will be greatly appreciated! I would imagine this could be a nice little challenge for those who seek it :)
Sincere thanks,
Try this:
Dim appExcel As Excel.Application
Set appExcel = CreateObject("EXCEL.Application")
Dim wkbk As Excel.Workbook
Set wkbk = appExcel.Workbooks.Open(sPathSrc, , False, , , sPassword)
' do EXCEL work here
If Not wkbk Is Nothing Then wkbk.Close True
Set wkbk = Nothing
If Not appExcel Is Nothing Then
appExcel.DisplayAlerts = False
appExcel.Quit
End If
Set appExcel = Nothing
This code is from an ACCESS application that invoked EXCEL to print some reports. I found it necessary to sprinkle some DOEVENTS calls around, but it was all a while ago; some details escape me at this moment.