A
angellijah
I need to take variables entered in an input box and use them in other
procedures within the project. After many failed attempts, I have this, but
it doesn't reset the variables with each instance. Any ideas? I tried Public
variables but it said I couldn't use them with a Sub or Function.
Public Sub filenames()
Dim WeekNumber, RegionName, Month, WeekNumberBox, RegionNameBox, MonthBox
WeekNumberBox = "Enter the fiscal two-digit week number"
RegionNameBox = "Enter the first three letters of the region name"
MonthBox = "Enter the first three letters of the current month"
'assign results
WeekNumber = InputBox(WeekNumberBox, , , 400, 400)
RegionName = InputBox(RegionNameBox, , , 400, 400)
Month = InputBox(MonthBox, , , 400, 400)
'assign results to document variables
For Each aVar In ActiveDocument.Variables
If aVar.Name = "weeknum" Then weeknum = aVar.Index
Next aVar
If weeknum = "" Then
ActiveDocument.Variables.Add Name:="weeknum", Value:=WeekNumber
Else
ActiveDocument.Variables(weeknum).Value = WeekNumber
End If
For Each aVar In ActiveDocument.Variables
If aVar.Name = "regname" Then regname = aVar.Index
Next aVar
If regname = "" Then
ActiveDocument.Variables.Add Name:="regname", Value:=RegionName
Else
ActiveDocument.Variables(regname).Value = RegionName
End If
For Each aVar In ActiveDocument.Variables
If aVar.Name = "mnth" Then mnth = aVar.Index
Next aVar
If mnth = "" Then
ActiveDocument.Variables.Add Name:="mnth", Value:=Month
Else
ActiveDocument.Variables(mnth).Value = Month
End If
procedures within the project. After many failed attempts, I have this, but
it doesn't reset the variables with each instance. Any ideas? I tried Public
variables but it said I couldn't use them with a Sub or Function.
Public Sub filenames()
Dim WeekNumber, RegionName, Month, WeekNumberBox, RegionNameBox, MonthBox
WeekNumberBox = "Enter the fiscal two-digit week number"
RegionNameBox = "Enter the first three letters of the region name"
MonthBox = "Enter the first three letters of the current month"
'assign results
WeekNumber = InputBox(WeekNumberBox, , , 400, 400)
RegionName = InputBox(RegionNameBox, , , 400, 400)
Month = InputBox(MonthBox, , , 400, 400)
'assign results to document variables
For Each aVar In ActiveDocument.Variables
If aVar.Name = "weeknum" Then weeknum = aVar.Index
Next aVar
If weeknum = "" Then
ActiveDocument.Variables.Add Name:="weeknum", Value:=WeekNumber
Else
ActiveDocument.Variables(weeknum).Value = WeekNumber
End If
For Each aVar In ActiveDocument.Variables
If aVar.Name = "regname" Then regname = aVar.Index
Next aVar
If regname = "" Then
ActiveDocument.Variables.Add Name:="regname", Value:=RegionName
Else
ActiveDocument.Variables(regname).Value = RegionName
End If
For Each aVar In ActiveDocument.Variables
If aVar.Name = "mnth" Then mnth = aVar.Index
Next aVar
If mnth = "" Then
ActiveDocument.Variables.Add Name:="mnth", Value:=Month
Else
ActiveDocument.Variables(mnth).Value = Month
End If