Previously filled-in value in Input Box should show up as default on re-running the macro

A

andreas

Dear Experts:

I created a macro that formats the footnote numbers at the bottom of
the page differently/seperately from the footnote reference marks in
the main body of the text. This is done by using Input Boxes. The macro
is running fine.

Now here comes my question: I would like the user to see the previously
filled-in value in the InputBoxes whenever he/she re-activates the
macro. Now, only the default values show up when the InputBoxes are
activated. Is there a solution ?

Sub Dipl_Footnote_Number_Format_Separately()
'Format footnote numbers separately

Dim FootnoteFontSize As String
Dim FootnoteFontPosition As String
Dim i as Byte

FootnoteFontSize = InputBox("Please indicate the font size of the
footnote number" & vbCrLf & _
"This will cause the footnote numbers to be formatted differently from
the footnote reference marks in the main body of the text", "Font size
of the footnote number", 9)

FootnoteFontPosition = InputBox("Please indicate the position of the
footnote number ", _
"Position the footnote number", 3)


Selection.GoTo What:=wdGoToFootnote, Which:=wdGoToFirst, Count:=1,
Name:=""
For i = 1 To ActiveDocument.Footnotes.Count

Selection.HomeKey unit:=wdLine
Selection.MoveRight unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Font.Superscript = False

Selection.Font.Size = FootnoteFontSize
Selection.Font.Position = FootnoteFontPosition

Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.GoTo What:=wdGoToFootnote, Which:=wdGoToNext, Count:=1,
Name:=""

Next i

End Sub

Again, my question: I would like the user to see the previously
filled-in value in the InputBoxes whenever he/she re-activates the
macro. Now, only the default values show up when the InputBoxes are
activated. Is there a solution ?

Help is appreciated. Thanks a lot in advance.

Regards,

Andreas
 
G

Greg Maxey

Something like this might work:

Store the value of the input box in a doc variable and then set the
defualt to the variable value:

Sub ScrathMacro()
Dim oVar As Variable
On Error GoTo Err_Handler
Set oVar = ActiveDocument.Variables("Store1")
oVar.Value = InputBox("Enter as value", "Value", oVar.Value)
FootNoteFontPostion = oVar.Value
Exit Sub
Err_Handler:
If Err.Number = 5825 Then
oVar.Value = "Default value"
Resume
End If
End Sub
 
A

andreas

Dear Greg,

great it is working, VERY GOOD JOB, BUT being more or less a novice at
VBA I do not know how to store the value of the second input box in a
second doc variable and then set the default to that variable value. I
tried a couple of things, but to no avail.

As you can see from the below code I integrated your code already but
as I said, the "FootnoteFontPosition" InputBox also needs to be
adressed.

Thank you in advance

Regards,

Andreas


Sub xxx_Format_Footnote_number()

'Your comments:
'Something like this might work:
'Store the value of the input box in a doc variable and then set the
'default to the variable value:



Dim oVar As Variable
Dim FootnoteFontPosition As String

On Error GoTo Err_Handler
Set oVar = ActiveDocument.Variables("Store1")
oVar.Value = InputBox("Enter as value", "Value", oVar.Value)

FootnoteFontPosition = InputBox("Please indicate the position of the
footnote", _
"Position footnote number", 3)

If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
ActivePane.View.Type = wdWebView Or
ActiveWindow.ActivePane.View.Type = _
wdPrintPreview Then
ActiveWindow.View.SeekView = wdSeekFootnotes
End If

Selection.GoTo What:=wdGoToFootnote, Which:=wdGoToFirst,
Count:=1, Name:=""
For i = 1 To ActiveDocument.Footnotes.Count

Selection.HomeKey unit:=wdLine
Selection.MoveRight unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Font.Superscript = False

Selection.Font.Size = oVar.Value
Selection.Font.Position = FootnoteFontPosition


Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.GoTo What:=wdGoToFootnote, Which:=wdGoToNext, Count:=1,
Name:=""
Next
Exit Sub

Err_Handler:
If Err.Number = 5825 Then
oVar.Value = "Default value"
Resume
End If
End Sub
 
G

Greg Maxey

Andreas,

Just repeat for the second variable what you do for the first:

Sub Dipl_Footnote_Number_Format_Separately()
Dim oVar1 As Variable
Dim oVar2 As Variable
Dim FootnoteFontSize As String
Dim FootnoteFontPosition As String

On Error GoTo Err_Handler1
Set oVar1 = ActiveDocument.Variables("Store1")
oVar1.Value = InputBox("Enter as value", "Value", oVar1.Value)
FootnoteFontSize = oVar1.Value

On Error GoTo Err_Handler2
Set oVar2 = ActiveDocument.Variables("Store2")
oVar2.Value = InputBox("Enter as value", "Value", oVar2.Value)
FootnoteFontPosition = oVar2.Value

'Your code to apply the variables defined above

Exit Sub
Err_Handler1:
If Err.Number = 5825 Then
oVar1.Value = "9"
Resume
End If
Exit Sub
Err_Handler2:
If Err.Number = 5825 Then
oVar2.Value = "3"
Resume
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top