Help: Opening Notepad after exporting to text file

Rhodess

New Member
Joined
Feb 24, 2013
Messages
11
I am sorting data in excel, then at the end I convert to a single column and then export it to a text file. Everything works except I cant get the text file to open automatically.

Can someone please help with the code below:
Sub Export2()
Dim r As Range, c As Range
Dim sTemp As String

'Declare constants for Desktop Location
Dim oWSS As Object
Const szlocation As String = "Desktop"
Dim szDesktopPath As String

' Get the desktop location
Set oWSS = CreateObject("WScript.Shell")
szDesktopPath = oWSS.SpecialFolders(szlocation)

' Open text file for output
Range("A1", Range("A1").End(xlDown)).Select
Open szDesktopPath & "\Fidelity.qif" For Output As #1
For Each r In Selection.Rows
sTemp = ""
For Each c In r.Cells
sTemp = sTemp & c.Text & Chr(9)
Next c

'Get rid of trailing tabs
While Right(sTemp, 1) = Chr(9)
sTemp = Left(sTemp, Len(sTemp) - 1)
Wend
Print #1, sTemp
Next r
Close #1

Shell "notepad.exe szDesktopPath & "\Fidelity.qif", vbNormalNoFocus
End Sub

I tried using the #1 variable but it can't find that and if I put the full path then it works, but I want to keep it generic.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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