I have a .bat that call a .vbs that reads from an Excel file here is what i have
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 2000
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\folder1\Folder2\MyExcel.xls")
set objsheet = objExcel.ActiveWorkbook.Worksheets(3)
OBJECT.SendKeys "Some Data."&""&objsheet.Cells(2,1).value &" " &objsheet.Cells(2,4).value
WScript.sleep 200
This works great my problem is different people will be using it so i need it to be able to run from the current location (%cd%)
THANKS!
You could try:
Application.ThisWorkbook.Path
Application.ThisWorkbook.FullName
Which returns for example:
C:\\Users\\d3ll_main\\Dropbox\\UNICEF CAR 2016\\Analysis
C:\\Users\\d3ll_main\\Dropbox\\UNICEF CAR 2016\\Analysis\\UnicefRCA_Analysis_v0.2.2.xlsm
Thisworkbook refers to the workbook where the VBA code lives - irrespective of the active workbook.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.