I'm in the process of a new program. My problem is that I'm trying to write so that a user is prompted one time (at set-up) for a variable - a path. After that they should never have to state it again. What I am experiencing using Option Explicit/ Public is that when I close and open the spreadsheet, it looses the variable and I have to re-do the 'one time only' InputBox. What am I doing wrong? I'm totally new at this... Thanks in advance.
Option Explicit
Public path As String
Sub InputBoxprompt()
'This will be used only when they are setting this up for the first time,
'or change their computers/network.
path = InputBox("Enter the Drive & Path that the forms reside on.")
Sheets("References").Range("A36").Value = path
End Sub
Sub printQRTRN05()
Dim wdapp As Object
Dim wddoc As Object
Set wdapp = CreateObject("Word.Application")
Set wddoc = wdapp.Documents.Open(FileName:=path & "QR-TRN-05_CommitmentLetter.docm")
'The above line is where I get prompted that it can't find the file.
'Ensure the Word application is visible.
wdapp.Visible = True
'Insert bookmark variables
With wdapp.ActiveDocument
.Bookmarks("FullName").Range.Text = Sheets("References").Range("B2").Value
.Bookmarks("SignonDate").Range.Text = Sheets("Main").Range("F4").Value
End With
'Print the doc
wdapp.ActiveDocument.PrintOut
'Give the print job 1 second to complete before closing Word.
Application.Wait Now + TimeSerial(0, 0, 1)
'Close the Word doc, no need to save changes.
wddoc.Close savechanges:=False
'Quit the Word application
wdapp.Quit
'Set the Object variables to Nothing to release system memory.
Set wddoc = Nothing
Set wdapp = Nothing
End Sub
If when I open the spreadsheet, I get prompted that it can't find the word doc. However, if I run the InputBox and put in the path variable, it will run fine until it crashes somewhere else. Is there a way to keep that variable in there 'forever'? So that when they close and open the program they don't have to keep using the InputBox? Thanks folks... Look forward to hearing from you.
Bookmarks