+ Reply to Thread
Results 1 to 5 of 5

Retrieving the path of my PnP device using VBA

  1. #1
    Registered User
    Join Date
    02-26-2020
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    3

    Retrieving the path of my PnP device using VBA

    Hello everyone !

    So I'm working on a macro that has to retrieve the path of my PnP device in order to run a .bat file. To call the bat file I use the Shell() function. Both of the doc (containing the macro) and the .bat are in the said PnP device.

    Before sending my doc and the bat to the my USB key, I tried it on my PC and everything runned smoothly. Since everything is on the key I can still retrieve the path (as shown in the code down bellow) but the bat file doesn't run because Shell() doesn't find the script.

    So hum... yeah... how can I get a valid path to the .bat for Shell() to run ?

    Please Login or Register  to view this content.
    As you can see I tried different methods to retrieve the path in hope it would be accepted by Shell() (Spoiler : it was no use :p).
    I hope my explanation was clear enough.

    Looking forward to your answer !

    PS : it's my first post on this forum, so tell me if I should post that somewhere else. Plus : I didn't find any thread discussing that particular question, but if I'm wrong I'd be more than happy to check it out
    Last edited by Bigard; 02-27-2020 at 08:36 AM.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Retrieving the path of my PnP device using VBA

    If the document and the batch file are in the same folder, then you should be using ActiveDocument.Path rather than a hardcoded path.
    Rory

  3. #3
    Registered User
    Join Date
    02-26-2020
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Retrieving the path of my PnP device using VBA

    Thank you for your answer.

    Actually I did try that solution. You can see the code line in my 1st post above (as a comment since I didn't want to lose it and wanted to show you I tried different solutions).

    Here is the said line :

    Please Login or Register  to view this content.
    So if I rewrite that part of the code, it will go like this

    Please Login or Register  to view this content.
    Once executed I get the error "5" which is "incorrect argument or call of procedure".


    By the way I tried something else since yesterday :
    Please Login or Register  to view this content.
    So what I'm trying to do with this is to literally call the shell, and make it run cmd after cmd in order to move from the C: drive to (in my case) D: drive (not glamorous, I think we can all agree on that).

    Once again the Shell function doesn't seem to understand several cmds as it returns the following error :

    Please Login or Register  to view this content.
    But I need to research a bit more about that.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Retrieving the path of my PnP device using VBA

    What path did filepath contain? You may need to enclose it in quotes:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-26-2020
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Retrieving the path of my PnP device using VBA

    Ok so I made it work !

    On my PC :
    filePath contained "D:\USB_Campaign"
    filePath1 contained only the first 2 caracters on the left, so : "D:"

    I saw the solution with the "quotes enclosure", but I tried this one first :

    Please Login or Register  to view this content.
    And it works !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using Excel File one device.
    By mazadb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2020, 05:39 PM
  2. Save to a USB device
    By labennett in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-25-2019, 05:00 AM
  3. Excel file use only one Device
    By mazadb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-30-2019, 05:08 AM
  4. In/Out Device tracking system
    By rogersjoe in forum Excel General
    Replies: 1
    Last Post: 11-19-2018, 01:58 AM
  5. [SOLVED] Retrieve USB Disk Device ID
    By freeofcost in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-20-2014, 03:43 PM
  6. EXT engaging when using an external 10-key device
    By Big TR in forum Excel General
    Replies: 1
    Last Post: 05-02-2007, 08:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1