0

I'm trying to pass a string into the command line once I've opened it via shortcut. (I had to open it up this way due to permission issues and OneDrive being weird.)

I understand the code for the most part. The problem is how to pass a string into command prompt once it's opened since I'm not doing it the traditional way.

Is there a method to pass a string into this so command prompt can automate stuff I input?

Sub OpenFile()

    Dim FileName As Variant
    Dim FolderItem As Object
    Dim FolderPath As Variant
    Dim oFolder As Object
    Dim oShell As Object
    'Dim UserName As String

    'UserName = InputBox("ex", "ex", "ex")
  
    FolderPath = [B]"C:\Documents and Settings\users\Command Prmompt"[/B]
    FileName = [B]"Command Prompt.lnk"[/B]
    
    Set oShell = CreateObject("Shell.Application")
    Set FolderItem = oShell.Namespace(FolderPath).ParseName(FileName)
    
    FolderItem.Verbs.Item(0).DoIt
    
End Sub
Community
  • 1
  • 1
Leafzer
  • 33
  • 7
  • Have you seen [Execute a command in command prompt using excel VBA](https://stackoverflow.com/questions/17956651/execute-a-command-in-command-prompt-using-excel-vba)? – Cyril Apr 07 '22 at 19:51
  • I have, but the issue with that is that calls cmd.exe from my onedrive. I need to specifically execute cmd the way I am here. FolderItem.Verbs.Item(0).DoIt is what is opening excel, I'm looking to see if there is another method I can add to that line that will pass a string once cmd is opened in this manner. – Leafzer Apr 07 '22 at 20:27

0 Answers0