Hi,
My .xlsm pastes a range to a .txt file.
What code can i use to prompt the user to rename & save the .txt file?
Thanks again
Mohamed
VBA Save Notepad File
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA Save Notepad File
Without knowing the code that you use, I can only provide an example of how to ask the user for a name:
Code: Select all
Dim strName As String
strName = Replace(ActiveWorkbook.FullName, ".xlsm", ".txt")
strName = Application.GetSaveAsFilename(strName, "Text files (*.txt),*.txt")
If strName = "False" Then
MsgBox "You didn't specify a filename!", vbExclamation
Exit Sub
End If
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
Re: VBA Save Notepad File
Hi Hans,
Didn't see your question in time.
Currently using this code to paste to notepad:
Sub Copy_To_Notepad ()
Range("e:e").Copy
RetVal = Shell("C:\WINDOWS\notepad.exe C:\Data V1.0\Data Batch Clearing\Data Import.txt", 1)
SendKeys "^v"
SendKeys "^a"
SendKeys "^c"
MsgBox "In NotePad Go To File: SAVE AS & Name the NotePad file" & vbCrLf & _
vbCrLf & _
"as per the Order Number.", vbOKOnly, "Save File"
End Sub
Second Question:
When this pastes to notepad the pasted range is highlighted/selected.
Is there a way to deselect in notepad with vba?
Thanks again
Mohamed
Didn't see your question in time.
Currently using this code to paste to notepad:
Sub Copy_To_Notepad ()
Range("e:e").Copy
RetVal = Shell("C:\WINDOWS\notepad.exe C:\Data V1.0\Data Batch Clearing\Data Import.txt", 1)
SendKeys "^v"
SendKeys "^a"
SendKeys "^c"
MsgBox "In NotePad Go To File: SAVE AS & Name the NotePad file" & vbCrLf & _
vbCrLf & _
"as per the Order Number.", vbOKOnly, "Save File"
End Sub
Second Question:
When this pastes to notepad the pasted range is highlighted/selected.
Is there a way to deselect in notepad with vba?
Thanks again
Mohamed
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA Save Notepad File
The line
SendKeys "^a"
selects all text in the Notepad file. If you omit this line (and the next, which isn't used), the text will not be selected.
SendKeys "^a"
selects all text in the Notepad file. If you omit this line (and the next, which isn't used), the text will not be selected.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
Re: VBA Save Notepad File
Thank you Hans.