Variable in Shell function

user125

New Member
Joined
Feb 20, 2020
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to use the Shell function and trying to make it dynamic by adding a string variable in the file path but I am having trouble doing so. Here is what I have so far:

VBA Code:
    Dim last as String
    Dim batchfolder as String
    
    last = Missing_Files.Range("B" & Rows.count).End(xlUp).row
    batchfolder = Console.Range("C56").Value
    
    If Missing_Files.Range("B" & last).Value = "AUD_UTACC_L&N_IBTSS" Then
    Shell ("batchfolder \ AUD_UTACC_L&N_IBTSS.bat")
    End If
    End Sub

The file path is entered in CELL 56 of worksheet Console. AUD_UTACC_L&N_IBTSS.bat is the name of the batch file I need to run. Please let me know if I can help with more information. Thanks in advance!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Anything you include between double-quotes is treated as literal text. So your batchfolder variable needs to be outside of them, i.e.
Shell (batchfolder & "\AUD_UTACC_L&N_IBTSS.bat")
 
Upvote 0
Anything you include between double-quotes is treated as literal text. So your batchfolder variable needs to be outside of them, i.e.
Shell (batchfolder & "\AUD_UTACC_L&N_IBTSS.bat")
Thanks Joe! That worked perfectly.
 
Upvote 0
You are welcome.

Just remember, literal text in quotes, variables outside of quotes, and you can combine them with &.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top