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
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