-1

Currently I am using hard-code PATH to a .EXCEL file in my Scripting language,Like as below:

    Set objExcel1 = CreateObject("Excel.Application")
    strPathExcel1 = "D:\VA\GE_Wing_To_Wing_Report.xlsx"
    Set objWB = objExcel1.Workbooks.open(strPathExcel1)

In VBScript is there any way to get such "D:\VA\ full path to any file on run-time?So that I can remove such hard-code from my script.

Thanks,

Community
  • 1
  • 1
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • What are you trying to avoid hardcoding? The actual file name? Did you want to open every file within the folder? If not, you can prompt the user following Siddharth's answer. – Daniel Dec 26 '12 at 16:32
  • @Danile If you see my code then you i have hardcoded the full path to the Excel to the variable`strPathExcel1`as `"D:\VA\GE_Wing_To_Wing_Report.xlsx"` . Where as I am looking for any way by which i can get the full path to the mentioned Excel `GE_Wing_To_Wing_Report.xlsx`. – Arup Rakshit Dec 26 '12 at 17:48

1 Answers1

3

You can use a filebrowser like the other answer suggests or an inputbox but both are anoying for the user, you could refer to just the filename without path if you put the excel file in the same map as the script, you can put this in a configuration file that you load in your main script or page or last you could give it to your script as a parameter which you can give in a console command or in a shortcut. let me know which you prefer, then i can give you an example.

EDIT: as promised, actually in the case of Excel it is a bit harder but not impossible, see this example

Set objExcel1 = CreateObject("Excel.Application")
objExcel1.visible = true
strPathExcel1 = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\GE_Wing_To_Wing_Report.xlsx"
Set objWB = objExcel1.Workbooks.open(strPathExcel1)
peter
  • 41,770
  • 5
  • 64
  • 108
  • file browser and input box I would prefer.Yes I will ask them to put all my 10 .vbs and Main.vbs to keep in the same directory. – Arup Rakshit Dec 26 '12 at 21:43
  • @vbsolver: Umm, you didn't say that you were going to keep the files in the same directory? If you are open to the idea then see the updated code (Followup) – Siddharth Rout Dec 26 '12 at 21:52
  • now Siddharth, not very nice to copy my answer the minute after i posted it, do you think people don't see this ? – peter Dec 26 '12 at 21:54
  • Whoa! I didn't copy your answer... your answer is different than mine' – Siddharth Rout Dec 26 '12 at 21:54
  • By Jove!... You are most welcome to take all the credit... I am deleting my entire post..... – Siddharth Rout Dec 26 '12 at 21:56
  • @peter I used last time similar solution but what i have seen, is that after the script is completed the Excel file didn't save anything ,all are blanks! – Arup Rakshit Dec 26 '12 at 22:00
  • @VBSlover, saving was not part of the question, you could google this up easily, try "vbscript excel saveas" – peter Dec 26 '12 at 22:08
  • Yes I know,I have opened a post also for the same,didn't get any response on that post! I then tried another workaround. Okay thanks for your all your help and informations! – Arup Rakshit Dec 26 '12 at 22:18