+ Reply to Thread
Results 1 to 12 of 12

UserName Variable

  1. #1
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    UserName Variable

    Hello,

    I'm trying to make a template file that will save to the correct pathway when either my co-workers or I use it. Right now, I'm declaring the variable in the main module with the following code.

    Please Login or Register  to view this content.
    Then calling the variable in about 4 other modules like this.

    Please Login or Register  to view this content.

    When I try to run the code, I'm getting a compile error. The error says Expected variable or procedure, not module.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: UserName Variable

    First thought is try making it a string, not a variant. However, would like to see the whole code together with what line it errors on.

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UserName Variable

    Hi,

    Did you change the name of your module to XqsId (or Path)?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: UserName Variable

    making it into a string didn't work. The main code errors out the first time I call the variable. Here is a little bit more of the code until it errors out when I call SAP

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: UserName Variable

    Quote Originally Posted by xlnitwit View Post
    Hi,

    Did you change the name of your module to XqsId (or Path)?
    Nope. Is that necessary?

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UserName Variable

    This code line
    Please Login or Register  to view this content.
    should be at the top of your code module, before any sub routines and should look like this
    Please Login or Register  to view this content.
    The error message you are getting would imply that your variable name is the same as the name of one of your modules.

  7. #7
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: UserName Variable

    Quote Originally Posted by xlnitwit View Post
    This code line
    Please Login or Register  to view this content.
    should be at the top of your code module, before any sub routines and should look like this
    Please Login or Register  to view this content.
    The error message you are getting would imply that your variable name is the same as the name of one of your modules.
    Ok this worked. It turns out I had two errors, I named some modules the same name as their Sub. Also I needed to declare the variable as Public.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: UserName Variable

    The method you're using won't work for everyone. You're making the assumption that everyone's desktop is in the same path, that isn't the case - something like the below is more reliable:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: UserName Variable

    Quote Originally Posted by Kyle123 View Post
    The method you're using won't work for everyone. You're making the assumption that everyone's desktop is in the same path, that isn't the case - something like the below is more reliable:
    Please Login or Register  to view this content.

    This is a little advanced for me. Does the code you provided just replace the Path of the Shell command? or does it replace the whole shell command?

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: UserName Variable

    It's the same as you already have:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-20-2017
    Location
    Indiana
    MS-Off Ver
    2016
    Posts
    101

    Re: UserName Variable

    Quote Originally Posted by Kyle123 View Post
    It's the same as you already have:

    Please Login or Register  to view this content.
    The code you provided doesn't work. It says the control could not be found by id. Let me know if you know what the problem is, but for now I'm going to stick to the old code that was working. I'll update this forum after I test the macro on another computer.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: UserName Variable

    Are you running this in SAP or Excel? - That's a SAP error message, not an Excel one

+ 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. [SOLVED] Can I use global variable to change password and username?
    By Goodstart14 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2016, 08:21 PM
  2. How Do I User Windows Variable Username with strFilePath?
    By kitchenspoon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-19-2016, 04:30 AM
  3. [SOLVED] Username and Password Form - Show Username in Sheet
    By ryan180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 07:06 PM
  4. Get username
    By famico78 in forum Excel General
    Replies: 1
    Last Post: 01-29-2011, 11:34 AM
  5. Get username
    By Schwizer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2007, 02:10 PM
  6. [SOLVED] UserName
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08:05 PM
  7. [SOLVED] Re: UserName
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08:05 PM

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