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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a text file with wordpad or word

Status
Not open for further replies.

nagyf

Programmer
May 9, 2001
74
HU
We make report as plain ASCII files then show them by Winword. Let the use format the report as she/he likes it!
We had a program line to open a text file
Shell "winword filename.txt".
WinWord was in the path, so it worked.
Somebody told that the presence of wordpad can be assumed but the presence of winword cannot at every user whom we want to install the program.
Shell "wordpad filename.txt" did not because
wordpad was not on the path.

My idea was: to search for wordpad during installation time then store its place in a variable the issue
Shell folder & "wordpad filename.txt"
Problem arose: space was in the folder name, so the above command needs doubled quotation marks or 8.3 counterpart of the folder name.

Any suggestions, please
Ferenc Nagy
|\ /~ ~~|~~~ nagyf@alpha0.iki.kfki.hu Fax: (36-1)-392-2529 New!
| \ | | Institute of Isotope and Surface Chemistry
| \ | -+- 1525 Bp. POB 77. Tel. :(36-1)-392-2550
| \| | `-' ' `-' "The goal of the life is the struggle itself"
 
I'm not sure what you mean by "8.3 Counterpart of the folder name" but to use Shell and files use something like the code below to zip a file:

Public Function ZipIT(varFileNames As Variant) As Boolean
'this function returns the success of zipping the files
'the input is an array of file names to zip
'***********************************************************
'*PROGRAMMER'S NOTE: the command line handler WZZIP *
'* must be installed and reside on the *
'* C Drive *
'***********************************************************
Dim sCmd As String
Dim varItm As Variant
Dim bSuccess As Boolean
Const cZIPFILE As String = "C:\CampData.zip"
Const cZIPEXE As String = "C:\WzZip"

On Error GoTo errHandler

bSuccess = True
sCmd = cZIPEXE & Chr$(vbKeySpace) & cZIPFILE & Chr$(vbKeySpace)
For Each varItm In varFileNames
sCmd = sCmd & CStr(varItm) & Chr$(vbKeySpace)
Next varItm

Call Shell(sCmd, vbNormalFocus)

errDone:
Err.Clear
ZipIT = bSuccess
Exit Function
errHandler:
bSuccess = False
Resume errDone
End Function

As you can see the chr$(vbKeySapce) gives you the spaces between commands. If you need to wrap in quotes add " & chr$(34) & " before and after any elements that need to be in quotes as:

shell (folder & chr$(34) & "winword blah blah" & chr$(34))

Sorry if this response is long and convulated but I hope this helps,

Rewdee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top