Referencing A Text Box

butch4343

New Member
Joined
Oct 25, 2018
Messages
1
Folks,

Im looking for some help , am new to VBA and I am trying to learn my way around Macros, I have an idea to create a word document (it has to be word not excel) I have a text box where the user enters a reference number every time the document is used. I first want to open an existing document in this case template1, (I have this nailed J )then save the document as the text in the reference Ie AB12345.doc , create a folder with the same AB12345 and save the document to new folder. The second part is to open an email with the subject as the contents of the textbox ie Sub:AB12345

I have helpfully found code online to do all of this, with one flaw, the code works perfectly when I designate the folder or document name in the code, what I am really really struggling with is getting the code to reference the text in the text box, it’s the key to making my whole project work and I am not getting it, I have tried using a really simple code to just create a folder and I can create a folder called “textbox1”

Is there a kind soul out there who might be generous enough to give this numpty a basic lesson in how to reference the content of textboxes? Bear in mind your speaking to a newby to coding so it needs to be in really basic steps.

I found a basic piece of code that creates a folder and wanted to use that to get my head around the text box issue.

https://www.ozgrid.com/forum/forum/...a-to-create-a-new-folder-from-a-textbox-value
Option Explicit

Private Sub CommandButton1_Click()

Dim newfol As String

newfol = TextBox1.Text & " "

ChDir "C:\shane"

On Error Resume Next

MkDir (newfol)

End Sub

I understand that I need to tell the code that the text box is a “thing” and it needs to be dimensioned as a string so would be something like
DIM as string
The next part confuses me a little, I need to give it a reference so it would be something like
newfol= textbox1.text
So if I was writing a path name to save the folder would it then look like
“C:\XXX\newfol”
I have also tried
“C:\XXX\textbox1” “C:\XXX\textbox1.text”
I did try a code that was “C:\XXX\textbox1&”””

But I got the following “expectation of a seperator


I am grateful for any help anyone out there can give me, its annoying that I cant get my head round this.

Mark
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top