Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open a blank notepad file from excel vba 2

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,051
US
How can I open a blank notepad text file from VBA within excel?

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"A fine is a tax for doing wrong. A tax is a fine for doing well.
" - unknown
 
not sure what you want to do exactly but here is an example of how to open a new .txt file and save the contents of a spreadsheet to that text file with each cell delimited with the | character.

Code:
Sub SaveAsPipeDelimited()
Dim r, c As Integer
Open "C:\Documents and Settings\sam\Desktop\Pipey.txt" For Output As #1
With ActiveSheet.UsedRange
   For r = 1 To .Rows.Count
      For c = 1 To .Columns.Count - 1
          Print #1, .Cells(r, c); "|";
      Next c
      Print #1, .Cells(r, .Columns.Count)
   Next r
End With
Close #1
End Sub
 
You may try this:
CreateObject("WScript.Shell").Run "notepad"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Once notepad is open is there a was to send it an immediate ctl-V (paste) command?

My code prior to opening notepad copies a selection of cells and I want to paste the values of these cells as text into notepad, then ultimately save it as a specific file name in a specific location.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"A fine is a tax for doing wrong. A tax is a fine for doing well.
" - unknown
 
Have a look at the SendKeys and AppActivate instructions.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
here is how i open it.

Just another way.

Shell "C:\WINDOWS\NOTEPAD.EXE", vbNormalFocus
 
I have looked at the SendKeys and AppActivate documentation but I am lost. Anything more concrete you can give me on how to paste data?

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"A fine is a tax for doing wrong. A tax is a fine for doing well.
" - unknown
 
x = Shell("notepad", 1)
AppActivate x
Application.SendKeys "^v"


should do it
 

Look at mscallisto's post again, you may want to use this way.

You make it too complcated by copy - paste into another app. In your Excell, instead of copy range, just open a text file, dump all data into it and you are done. mscallisto gave you the code - use it.

ANd you don't have to worry about the best way to open notepad, how to paste it, and then figure out how to save it with the right name in the right location. Make it easy.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top