Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a TextBox value in a file String
I have the following code ina standard module, the user can enter there own
file name via a form. Sub The_SubSave() Dim fName As String fName = frmOptions.TextBox1.Value If frmOptions.CheckBox2.Value = False Then ActiveWorkbook.SaveCopyAs "C:\AutoSaves" & "fName" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Else ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" End If StartTimer End Sub The problem is if the checkbox is false the first if statement which include the textbox value as part if the file path does'nt work. Ive trie placing in( ) and " " of having the tectbox in the string but it does not wok! The Else option works fine! Does anyone have any suggestions Thanks in advance for any help |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a TextBox value in a file String
Hi
fName is already a string so you want to use fName not "fName" You also have a periods (.) in the middle of your strings , as well as the one in front of your xls at the end. This is a file name no no so you should remove them. regards Paul On Mar 9, 11:49 am, Mark Dullingham wrote: I have the following code ina standard module, the user can enter there own file name via a form. Sub The_SubSave() Dim fName As String fName = frmOptions.TextBox1.Value If frmOptions.CheckBox2.Value = False Then ActiveWorkbook.SaveCopyAs "C:\AutoSaves" & "fName" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Else ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" End If StartTimer End Sub The problem is if the checkbox is false the first if statement which include the textbox value as part if the file path does'nt work. Ive trie placing in( ) and " " of having the tectbox in the string but it does not wok! The Else option works fine! Does anyone have any suggestions Thanks in advance for any help |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a TextBox value in a file String
Thanks for your reply.
The () in the in the string are there to define the 2 format statements abd don't appear in the file name. If called for - ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Works fine. What I want to do is replace DDE Sheet with the fname , manely the value of textbox1, but in it's current format it doesn't wor!! " wrote: Hi fName is already a string so you want to use fName not "fName" You also have a periods (.) in the middle of your strings , as well as the one in front of your xls at the end. This is a file name no no so you should remove them. regards Paul On Mar 9, 11:49 am, Mark Dullingham wrote: I have the following code ina standard module, the user can enter there own file name via a form. Sub The_SubSave() Dim fName As String fName = frmOptions.TextBox1.Value If frmOptions.CheckBox2.Value = False Then ActiveWorkbook.SaveCopyAs "C:\AutoSaves" & "fName" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Else ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" End If StartTimer End Sub The problem is if the checkbox is false the first if statement which include the textbox value as part if the file path does'nt work. Ive trie placing in( ) and " " of having the tectbox in the string but it does not wok! The Else option works fine! Does anyone have any suggestions Thanks in advance for any help |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a TextBox value in a file String
Maybe something like:
ActiveWorkbook.SaveCopyAs "C:\AutoSaves\" & fname & _ & "." & Format(now, "dd-mmm-yyyy.hh-mm-ss") & ".xls" or (Since I'm confused): ActiveWorkbook.SaveCopyAs "C:\AutoSaves\" & textbox1.text & _ & "." & Format(now, "dd-mmm-yyyy.hh-mm-ss") & ".xls" (I changed the date and time to now, too.) Mark Dullingham wrote: Thanks for your reply. The () in the in the string are there to define the 2 format statements abd don't appear in the file name. If called for - ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Works fine. What I want to do is replace DDE Sheet with the fname , manely the value of textbox1, but in it's current format it doesn't wor!! " wrote: Hi fName is already a string so you want to use fName not "fName" You also have a periods (.) in the middle of your strings , as well as the one in front of your xls at the end. This is a file name no no so you should remove them. regards Paul On Mar 9, 11:49 am, Mark Dullingham wrote: I have the following code ina standard module, the user can enter there own file name via a form. Sub The_SubSave() Dim fName As String fName = frmOptions.TextBox1.Value If frmOptions.CheckBox2.Value = False Then ActiveWorkbook.SaveCopyAs "C:\AutoSaves" & "fName" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Else ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" End If StartTimer End Sub The problem is if the checkbox is false the first if statement which include the textbox value as part if the file path does'nt work. Ive trie placing in( ) and " " of having the tectbox in the string but it does not wok! The Else option works fine! Does anyone have any suggestions Thanks in advance for any help -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a TextBox value in a file String
Dave,
Thanks a million, both your suggestions worked great. That was the last thing I had to get working on this project and it's been frustrating me for days. Thanks for taking the time to reply, much appreciated. Mark "Dave Peterson" wrote: Maybe something like: ActiveWorkbook.SaveCopyAs "C:\AutoSaves\" & fname & _ & "." & Format(now, "dd-mmm-yyyy.hh-mm-ss") & ".xls" or (Since I'm confused): ActiveWorkbook.SaveCopyAs "C:\AutoSaves\" & textbox1.text & _ & "." & Format(now, "dd-mmm-yyyy.hh-mm-ss") & ".xls" (I changed the date and time to now, too.) Mark Dullingham wrote: Thanks for your reply. The () in the in the string are there to define the 2 format statements abd don't appear in the file name. If called for - ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Works fine. What I want to do is replace DDE Sheet with the fname , manely the value of textbox1, but in it's current format it doesn't wor!! " wrote: Hi fName is already a string so you want to use fName not "fName" You also have a periods (.) in the middle of your strings , as well as the one in front of your xls at the end. This is a file name no no so you should remove them. regards Paul On Mar 9, 11:49 am, Mark Dullingham wrote: I have the following code ina standard module, the user can enter there own file name via a form. Sub The_SubSave() Dim fName As String fName = frmOptions.TextBox1.Value If frmOptions.CheckBox2.Value = False Then ActiveWorkbook.SaveCopyAs "C:\AutoSaves" & "fName" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" Else ActiveWorkbook.SaveCopyAs "C:\AutoSaves\DDE Sheet" _ & "." & Format(Date, "dd-mmm-yyyy") & "." & Format(Time, "hh-mm-ss") & ".xls" End If StartTimer End Sub The problem is if the checkbox is false the first if statement which include the textbox value as part if the file path does'nt work. Ive trie placing in( ) and " " of having the tectbox in the string but it does not wok! The Else option works fine! Does anyone have any suggestions Thanks in advance for any help -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
textbox to file (.txt or .doc) | Excel Programming | |||
need to add string to txt file | Excel Programming | |||
HELP! I Lost The Ability To Advance From TextBox To TextBox With the ENTER Or The TAB Keys | Excel Programming | |||
Retaining value of a string from a textbox on a form ?? | Excel Programming | |||
Textbox & Save file problem | Excel Programming |