+ Reply to Thread
Results 1 to 13 of 13

Combining 2 String Variables

  1. #1
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Combining 2 String Variables

    Hello,

    I'm putting together code that will attach a PDF to an email in Lotus Notes and send. However I'm having difficulty with the path of where the PDF is saved. I have two cells in Excel A1 which is the File Path and A2 which is the File name. Each of these are defined strings, SAVE_PATH and FILE_NAME.

    Please Login or Register  to view this content.
    When I test the code, it comes back as Attachment1 = "SAVE_PATHFILE_NAME" rather than "C:My Documents\Directory\Test_Analysis.pdf"

    I have a feeling I'm missing something incredibly basic here, I just can't for the life of me figure it out.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Combining 2 String Variables

    Range("SAVE_PATH") & Range("FILE_NAME")
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Re: Combining 2 String Variables

    Hello, thank you for the replies! When I add the Range syntax I receive Run-time error '1004'; Method of 'Range' of object '_Global' failed. When I debug it shows that each of the variables SAVE_PATH and FILE_NAME are associated with the correct strings of data.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    ... associated with the correct strings of data.
    And what are those strings of data?

  6. #6
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Re: Combining 2 String Variables

    In debug, when I hover over SAVE_PATH it reflects "C:My Documents/Directory/" and when I hover over FILE_NAME it reflects "Test_Analysis.pdf". When these strings are typed together in:

    Please Login or Register  to view this content.
    The code is successful.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    SAVE_PATH it reflects "C:My Documents/Directory/" and when I hover over FILE_NAME it reflects "Test_Analysis.pdf"
    I think SAVE_PATH should be "C:\My Documents\Directory\"


    Regards, TMS

  8. #8
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Re: Combining 2 String Variables

    I fixed that oversight, however I'm still receiving the same Run-time error as before. I've mocked up an example with this code to highlight the error. I appreciate your assistance!
    Attached Files Attached Files

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    What version of Windows are you using? Normally, the My Documents folder is a sub-folder of the user directory. For example: C:\Users\Trevor\Documents

    I'm not sure of the value of your "definer" functions. It would be easy for you, or anyone else to break the code by changing any of the text strings that you search for. And, really, it's unnecessary code. You would be far better off defining Named Ranges for all those references. You could hide the Named Ranges using VBA so only you know they exist an to what they refer. Less chance of them being corrupted unless the actual cell/row/column is deleted.

    Regards, TMS

  10. #10
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Re: Combining 2 String Variables

    Windows 7, the file path is fine because when I hard code the path in everything works well. I think I'm going to take your advice and rewrite the code to be based on Named Ranges. Thanks for your assistance!

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    This can't be right: "C:\My Documents\Directory\" .... unless you have created a separate My Documents folder in the C:\ drive

  12. #12
    Registered User
    Join Date
    06-12-2014
    Posts
    19

    Re: Combining 2 String Variables

    I did create a separate My Documents folder in C for easier access rather than having to drill through multiple sub-folders. When I went back and created the named ranges as you suggested the code worked beautifully, thank you!

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Combining 2 String Variables

    Fair enough!

+ 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. How to perform various calculations and combining two variables
    By Even in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-01-2013, 11:28 AM
  2. Different Variables combining in formulas
    By beginnerexcel in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-09-2011, 12:44 AM
  3. Combining code using variables
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 06-07-2011, 07:57 AM
  4. passing a string array and string variables to sub
    By Lokesh_g in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-04-2010, 09:26 PM
  5. Replies: 4
    Last Post: 10-28-2009, 04:28 PM

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