I am attempting to use VBscript to open an excel file. However, when I run the script, it says the file cannot be located. I am pretty certain I have the file path correct. Is it possible that something else is causing my code to fail?
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook =
objExcel.Workbooks.Open("C:\Users\Guest\Documents\Projects\1A.xlsx")
Set objExcel = Nothing
Set objWorkbook = Nothing
As mentioned in the comments
In 9 out of 10 cases, this is permission related
The likeihood is (if you have already confirmed the file path is correct) that the VBScript does not have the permission required to access the file path, but due to the way elevation works along with UAC on most Windows Operating Systems means that VBScript doesn't know about the path, so it isn't reported as a access permission error.
As the path in question refers to a User Profile path the chances of it being permissions related increases.
To fix the problem the host process running the VBScript (wscript.exe or cscript.exe) needs to be run using elevated privileges. You can do this by opening an elevated command prompt (Run as Administrator context menu option) and specifying the host process followed by the script path.
Something like;
cscript.exe "yourscript.vbs"
From a windows command prompt type
c:\ dir C:\Users\Guest\Documents\Projects\1A.xlsx
The file could have been saved with a different file extension, or if explorer is hiding extensions and a user has provided the extension on save it might be called 1A.xlsx.xslx
Windows explorer might be hiding data. If you can see it in explorer, right click the file > properties > details.
The Name attribute should tell you exactly what the file is named on disk and the Folder path should give you the path.
You can combine the two to give the full path to the file on disk
Related
I have a .vbs script that opens two excel files and copies the contents of a sheet from the first file into the second file. It's supposed to run daily via task scheduler.
The script ran normally until the excel files in question were recently modified and slightly renamed - I went through the script and edited the filenames accordingly after the changes were made, triple checking that the names and filepaths matched up.
Everything ran fine for a few weeks after the changes but now the script fails immediately after starting, giving me an error claiming that the file can't be located even though the file is located at the given path. The error code is 800A03EC.
This is the first chunk of code in the script, including line 7 which seems to be throwing the error:
Dim objApp ' as excel object
Dim x, y ' as workbook
Set objApp = CreateObject("Excel.Application")
objApp.DisplayAlerts = False
objApp.Visible = False
Set x = objApp.Workbooks.Open("S:\Work (Public)\PORT MGMT & TRADING\PORT MGMT FORMS\ORION_FPFOCUS.xlsm")
Set y = objApp.Workbooks.Open("S:\Work (Public)\PORT MGMT & TRADING\PORT MGMT FORMS\FPFocusPasteSpecialValues.xlsb")
Dim WSx, WSy ' as excel worksheet
Set WSx = x.Worksheets("FPSUP")
Set WSy = y.Worksheets("FPFOCUS-COPY")
WSy.Range("B1").value = FormatDateTime(Now)
objApp.Application.Run "ORION_FPFOCUS.xlsm!Auto_Open"
The excel files in question are both located in the same directory:
S:\Work (Public)\PORT MGMT & TRADING\PORT MGMT FORMS\ORION_FPFOCUS.xlsm
S:\Work (Public)\PORT MGMT & TRADING\PORT MGMT FORMS\FPFocusPasteSpecialValues.xlsb
And the script is located here:
C:\Users\bserv\Documents\CopyFPFocus.vbs
The S drive isn't a physical drive, it's a virtual drive hosted by a service called Workplace. I can navigate through it and open the excel files manually just fine.
I initially thought it was a user privilege issue with task scheduler, but I've selected the 'run with highest privileges' option and the script is still failing. I also went through the privacy/trust settings in Excel to make sure the script wasn't being denied access, but I don't see any settings that would disable the script from working, and I also know that all these settings haven't changed since the script was working, so I don't see how they could be potential causes.
When I try running the code manually via cscript in the command line, it returns this error:
C:\Users\bserv\Documents\CopyFPFocus.vbs(25, 4) (null): The remote procedure call failed.
This is line 25 of the script for reference:
objApp.Run "RefreshAllStaticData"
When I try again by running command prompt as an admin, I get the same error I got initially. Sorry, is it possible the file was moved renamed or deleted.
The part that really confuses me is that the script ran fine for some time after the changes - so I'm really unsure about what actually changed to cause this issue to randomly pop up.
One other thing I've noticed is that upon opening the excel files I get a popup saying they're in use and locked for editing by me. I can't remember if this popup was showing up before the issue started. The other users on the network have been accessing these files regularly long before the script started failing, so I don't see how that could be the issue. The error code/message also doesn't seem to correspond with this being the problem.
I'd appreciate any help or insight into this issue. Thank you!
I am trying to make a macro variable in SAS Studio which saves the "present working directory" as a macro variable.
The SAS-program is run in a "CPF" process flow file in SAS Studio, and the whole SAS-file and processes are saved and run in a Linux server.
In SAS-Studio, the location of CPF-process flow file seems like in the directory /sasdata/model_v1, and when I run a Linux command like X "pwd" then I expect that the result will give /sasdata/model_v1, but I get another directory instead like /sasinstall/sasconfig/Lev1/SASApp instead, I guess the the process flow file with CPF-suffix is run from this directory.
So the question is how I can find and save the working directory of my cpf-file and save as a macro-variable, or even maybe for my other sas-files too, I may need the solution for both SAS-files and CPF-files.
If I find the directory, then I guess it should be enough to save them as macro-variable by using %let macrovariable = "/directory"
I don't think SAS will show you the path of the process file. It doesn't in SAS/Studio 3.5.
It will set the path for a normal program file (as long as you have saved it) in the _SASPROGRAMFILE macro variable.
We currently have Office 2010 and are moving to Office 2016. I have an Excel macro that I am try to testing. I use the following shell command to open access and run a macro to import some excel files into a database. This has worked great and never has any issues.
Shell "C:\PROGRA~1\MICROS~1\Office14\MSACCESS.EXE \\Vs300\rental_public\SHARED~1\SSDATA~2.MDB /X Upload_Manheim", vbMaximizedFocus
When I look for the Access application on my machine the path is as follows:
C:Program Files\Microsoft Office\Office14
When I search for the Access application on the test machine, the path is as follows:
C:Program Files (x86)\Microsoft Office\root\Office16
I've tried modifying the shell command as follows:
Shell "C:\PROGRA~1\MICROS~1\root\Office16\MSACCESS.EXE \\Vs300\rental_public\OFFICE~1\SHARED~1\SSDATA~1.MDB /X Upload_Manheim", vbMaximizedFocus
When I try to run my macro, I'm getting a file not found error message. I believe the 2nd half of the shell command is fine, so I believe it is the issue is in the 1st half of the shell command.
The database being opened is an Access 2000 database. I'm not sure what is wrong.
Instead of going thru the command line you could stay inside your Excel Macro and do the same without making reference to the location of the Access application. Instead you can create a new instance of MS Access from within vba, open the Access database the contains the macro, and then run the macro.
Something like:
Dim accApp As Access.Application
Dim db As Object
Set accApp = CreateObject("Access.Application")
accApp.OpenCurrentDatabase "Your database location\dbName", True
Set db = accApp.CurrentDb
With db
DoCmd.RunMacro "MacroNameHere"
End With
Set accApp = Nothing
Set db = Nothing
Good luck!
I'm running into a "Grant Access" problem with Office 2016 where I have to manually click "Grant Access" if I'm opening a new file with Automator. I found this answer for how to get around it (by using a file object or an alias object instead of a string):
tell application "Microsoft Excel"
activate
open file "Macintosh HD:Users:path:to:file"
end tell
But since I'm using an Automator folder action, I'm not sure how to get that file path where it needs to be. Most of the examples I found has the AppleScript use choose folder with prompt but since the whole point of this is to be fully automated, that's not going to work.
The idea is:
Excel file gets downloaded into "ForSQL" folder
Folder action prompts xls file to convert into csv
csv then opens in TextWrangle to ensure it stays in UTF-8
Then moves it to official "SQL" folder
Closes all the applications it opened and deletes whatever it moved from the "ForSQL" folder
But I'm open to better suggestions that get to the same end result.
This is my Automator workflow so far -- but it looks like I need to replace the 'Convert Format of Excel Files' step with AppleScript to get the "Grant Access" pop-up to go away. It's a folder action that starts when something hits the "ForSQL" folder:
I am not sure to understand what you want to do with textWrangle, but the script bellow does all steps before and after, only using Applescript (no need for Automator actions) :
--this choose file must be replaced by your "input" of automator folder items
set Fxl to choose file --the Excel file to be processed
-- define here your destination SQL folder
-- for my tests, I used a folder mySQL on my Desktop
set SQLFolder to ((path to desktop folder) as string) & "mySQL"
tell application "Finder" to set ForSQL to (container of Fxl) as string
--define new name by replacing current extension (xls, xlsx, xlsm, xml) by "csv"
tell application "Finder"
set N to name of Fxl
set NbExt to length of ((name extension of Fxl) as string)
set newname to (text 1 thru -(NbExt + 1) of N) & "csv"
end tell
--convert to CSV and close
tell application "Microsoft Excel"
open Fxl
tell workbook 1
tell sheet 1 to save in (ForSQL & newname) as CSV file format
close without saving
end tell
end tell
-- add eventually your TextWrangle step here (?)
-- delete source file and move csv to proper folder
tell application "Finder"
delete Fxl
move file (ForSQL & newname) to folder SQLFolder
end tell
In practice you can run all this in full applescript folder action.
Replace the "set Fxl to choose..." by "on adding folder items...".
In this case you must insert the script above in a repeat loop to process all files drops in the folder.
However, you may have some issues using folder action script, because system will trigger your script again at the time you are creating the new CSV file (again in the same folder !).
The work around I suggest is to use folder action script to get the file dropped in ForSQL, move it to an other "temp_ForSQL" and run this script using the moved file. Doing so, the cvs will be added to temp_forSLQ, without triggering new folder action script.
I hope it is clear enough...if not, just let me know.
I am running a perl script file from c# application using IIS, in that I want to open a already existing Excel file and I am opening it using the following line:
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";//upto this working fine
$book = $ex->Workbooks->Open($fileName); //this line only giving error
Now I am getting the error in the open as follows:
OLE exception from "Microsoft Office Excel":
Microsoft Office Excel cannot access the file
'C:\GWATS\Report\Nov-17-2014_10-06-36\GES-11n_IOT_10-06-37.xls'. 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.
Win32::OLE(0.1711) error 0x800a03ec
in METHOD/PROPERTYGET "Open" at C:\GWATS\Lib\System\Report.pm line 611.
The file is surely present I verified that.
Also this script is working fine when I directly run that in cmd. What is the problem here, I think the problem is with IIS but I could find what exactly the problem is?
Try the below perl script. If still some error exists let me know:
Code:
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
my $filename = 'C:\GWATS\Report\Nov-17-2014_10-06-36\GES-11n_IOT_10-06-37.xls'
my $book = $Excel->Workbooks->Open($filename);
Open Windows Explorer
Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following:
32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile
Verify the folder "Desktop" exists (create it if it's not there)
Right click > Properties
On the security tab: Add the account under which the site is running (eg: DefaultAppPool) with default permissions (Read & execute; List folder contents; Read)
i faced similar issue
it worked for me when i gave the absolute path for the files