+ Reply to Thread
Results 1 to 6 of 6

VBA to Save as with variable string name

  1. #1
    Registered User
    Join Date
    08-08-2017
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    VBA to Save as with variable string name

    Appreciate any help in advance.

    I have a VBA code below that finds a specific text and then copies the numbers next to it in Microsoft Word. where it is failing which i'd need help with is saving the current opened document as PDF using the string name. I receive a runtime error: This is not a valid Filename

    Please Login or Register  to view this content.
    appreciate any help.
    Lucas

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: VBA to Save as with variable string name

    What are the values of strPath & myNum when the error occurs?

    There are several places a problem could be introduced here but it's not possible to diagnose without knowing what you expect this code to do and also sample data to see if the code is correct.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-08-2017
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    Re: VBA to Save as with variable string name

    Thank you for your reply Jeff.

    I've exchanged the code to save as below.
    HTML Code: 
    myNum is a number always, example is 111 111 111

    When I do msgbox myNum I get 111 111 111

    when I change the value Mynum to below it saves it as Test_File and works fine. so it must be some formatting with myNum as there maybe an enter or extra space.

    HTML Code: 
    MSGBOX.gif
    myNum.gif
    Last edited by EverBalzing; 05-19-2021 at 08:46 AM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: VBA to Save as with variable string name

    Is it possible that myNum contains a non-printing character? I would do this:

    Please Login or Register  to view this content.
    Then show us what prints in the Immediate window.

  5. #5
    Registered User
    Join Date
    08-08-2017
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    Re: VBA to Save as with variable string name

    Attachment 733267

    Thank you for your reply. Please find above attached screenshot.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: VBA to Save as with variable string name

    The final character is a carriage return character, not valid in a file name. I can't figure out your logic for assigning myNum so it's hard for me to tell you how to fix it. The brute force method would be to add this line of code after setting myNum:

    Please Login or Register  to view this content.

+ 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. trying to convert string variable to barcode font and store as new string var
    By mike_tako in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 05-11-2018, 04:36 PM
  2. [SOLVED] How to extract a piece of a string variable, and assign to a new variable
    By jmccoughlin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2015, 11:50 PM
  3. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  4. [SOLVED] Attachments : Save and Rename using Sublect string or File name string
    By checksamir in forum Outlook Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2014, 01:13 AM
  5. save file path as string variable
    By schzuki in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2014, 06:02 AM
  6. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  7. Transferring a dynamically named string variable to another string variable.
    By Concorde Rules in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2012, 04:08 AM

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