+ Reply to Thread
Results 1 to 2 of 2

Passing Arguments Between Spreadsheets

Hybrid View

nt180792 Passing Arguments Between... 11-14-2009, 11:07 AM
Richard Buttrey Re: Passing Arguments Between... 11-14-2009, 02:26 PM
  1. #1
    Registered User
    Join Date
    03-19-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    Passing Arguments Between Spreadsheets

    Hello all,

    I have two spreadsheets that i'm using for a project. One of them controls the customer end and one the staff end. When a button is clicked on the customer spreadsheet, is it possible to open up the staff spreadsheet and pass along arguments (variables)in the process, to use on the staff spreadsheet?

    If so, can someone please inform me on how you would do it.

    Thanks in advance,
    Nick.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Arguments Between Spreadsheets

    Hi Nick,

    Yes, when you call another procedure it is sufficient just to name the procedure in the macro. So for instance assuming your procedure for opening staff spreadsheets is called 'OpenStaffSpreadsheet' you would have:

    Sub MyFantasticProcedure
    
    'your code
    
    OpenStaffSpreadsheet
    
    'code continued
    However when you pass arguments you need to preface the procedure name with 'Call' and include the arguments in brackets at the end of the name. So suppose you wanted to pass say a staff ID number 12345, and a location 'London' you would have the following

    Sub MyFantasticProcedure
    
    'your code
    
    Call OpenStaffSpreadsheet(12345,"London")
    
    'code continued
    and your OpenStaffSpreadsheet procedure would look like:

    Sub OpenStaffSpreadsheet(iStaffID as Integer, stLocation as String)
    
    'your code which can now use the values 12345 and London by specifying
    ' iStaffId and stLocation e.g.
    
    Range("A1") = stLocation
    Range("C1") = iStaffID
     
    
    
    End Sub
    Personally I always prefer to use the Call instruction whether I am passing arguments or not. I find it easier to spot procedure names

    HTH
    Last edited by shg; 11-14-2009 at 03:15 PM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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