Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. passing data between procedures

passing data between procedures

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matthew Leggett
    wrote on last edited by
    #1

    I am trying to get a variable to pass to another procedure. I have set my procedure as follows Sub Procedure(X) ' programming code End Sub Normally I would use the following to send data Procedure1 Count6 however in this case I am running the called procedure using this code With ActiveWorkbook.Sheets(SetMonth).Buttons.Add(600, 20, 100, 25) .OnAction = "Procedure1" .Caption = "Bills Not Paid July" .Name = "JULY" End With how do I adapt the ".OnAction = "Procedure1" section to pass the variable" Can anyone help me

    C 1 Reply Last reply
    0
    • M Matthew Leggett

      I am trying to get a variable to pass to another procedure. I have set my procedure as follows Sub Procedure(X) ' programming code End Sub Normally I would use the following to send data Procedure1 Count6 however in this case I am running the called procedure using this code With ActiveWorkbook.Sheets(SetMonth).Buttons.Add(600, 20, 100, 25) .OnAction = "Procedure1" .Caption = "Bills Not Paid July" .Name = "JULY" End With how do I adapt the ".OnAction = "Procedure1" section to pass the variable" Can anyone help me

      C Offline
      C Offline
      ChandraRam
      wrote on last edited by
      #2

      Hi The issue with specifying the parameter when you create the button is that the value for the parameter will be fixed. For instance:

      Public Sub CreateButton()
      With ActiveWorkbook.Sheets("sheet1").Buttons.Add(600, 20, 100, 25)
      .OnAction = "'Procedure1 ""Hello"", " & nCount & "'"
      .Caption = "Bills Not Paid July"
      .Name = "JULY"
      End With
      End Sub

      Public Sub Procedure1(ByVal s As String, ByVal x As Integer)
      MsgBox s & " " & x
      End Sub

      In the code above, even though the parameter is specified as a variable, the value when you _define_ the OnAction is what will be passed in. To get around this, you could try this:

      Public Sub CreateButton()
      With ActiveWorkbook.Sheets("sheet1").Buttons.Add(600, 20, 100, 25)
      .OnAction = "July_Click"
      .Caption = "Bills Not Paid July"
      .Name = "JULY"
      End With
      End Sub

      Public Sub July_Click()
      Call ActiveWorkbook.Application.Run("Procedure1", "test", nCount)
      End Sub

      Public Sub Procedure1(ByVal s As String, ByVal x As Integer)
      MsgBox s & " " & x
      End Sub

      HTH

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups