View Single Post
 
Old 06-14-2019, 10:36 AM
DaveP DaveP is offline Windows 10 Office 2010
Novice
 
Join Date: May 2019
Posts: 11
DaveP is on a distinguished road
Default Input Box Help/Storing Variables in other Macros

Hello,
(start at the ** if you don't care about context)

I wrote a program that uses userforms to open up documents from our file explorer and network, as well as run simple macros (mostly formatting). The goal is to save time; we open 5 or 6 different documents on every case, and do ~20 cases per day, so having a userform that offers you those documents, rather than dig through 6 different folders, is a huge deal (believe, me I understand how inefficient that all sounds, but if you knew what we do, it makes sense, I promise, ha).

I'm trying to build a macro that will open a document that has not been created yet. Let's call it AutoText. The department that creates AutoText has not yet made the doc, but I don't want to have to update the user's copy of the program every time we write a new AutoText document, if that makes sense.

*********Basically, I want an input box where you paste a file location, and what you pasted gets added to a macro that opens that file location, and stores the file location for future use.

Sub Send()
InputBox ("File Location: click the files tab; underneath the document title, click the file path, then click 'Copy Path to Clipboard'")
'What goes here? How do I paste to "Sub Receive"?
End Sub

Sub Receive()
'Auto Texts file opener
Shell "Explorer.exe ***the file location entered in the Sub Send input box***", vbNormalFocus
End Sub


So the user would input

C:\Users\davep\Desktop\Files\AutoText.docx

and press enter, and then Sub Receive would now say:

Sub Receive()
'Auto Texts
Shell "Explorer.exe C:\Users\davep\Desktop\File\AutoText.docx", vbNormalFocus
End Sub


Now, in the userform, I have a command button:

Private Sub CommandButton4_Click()
Call Receive
Me.hide
End Sub

So after inputting the file location in Sub Send, Sub Receive now opens AutoText.docx, and when you click CommandButton4, Sub Receive runs, opening AutoText.docx.

TL;DR:
I have an Input box, I want the user to add a file location, it stores the file location to a macro, with a shell command that opens that file location--- that macro is called upon by a command button attached to a userform. How do I store an input box answer inside of an existing macro?
Reply With Quote