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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,563
Messages
6,125,572
Members
449,237
Latest member
Chase S

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