PDA

View Full Version : [SOLVED:] Dynamically passing value to Sub using buttons



mongoose
07-30-2019, 08:17 AM
I'm trying to pass a value to a Sub using this code..



With btn
.OnAction = "GenerateAuditFile(" & i & ")"
.Caption = "Generate"
.Name = "btnsGenerateAudit " & i
End With


But, I'm doing something wrong. I think it's my syntax.

Paul_Hossler
07-30-2019, 09:41 AM
Option Explicit

Dim i As Long

Sub Setup()
i = 1
With Worksheets("Sheet1").Shapes(1)
.OnAction = "'GenerateAuditFile " & i & "'" ' <<<<<<<<< note single quotes and spaces
.TextFrame.Characters.Text = "Generate" & i
.Name = "btnsGenerateAudit " & i
End With
End Sub


Sub GenerateAuditFile(i As Long)

MsgBox i
End Sub