|
-
April 24th, 2002, 10:05 AM
#1
variable vs "text"; How can I put the variable of "xxx" instead of "xxx", if "xxx" must be "xxx", no
Hi,
I'd like to replace "D:\Test\test.txt" with SelectedFile (a variable storing drive, directory, file names). But if I put SelectedFile on the spot where "D:\Test\test.txt" exists, I get an error.
How can I deal with this problem?
'/////////////////////
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Set w = CreateObject("Word.Application")
SelectedFile = File1.FileName
w.Documents.Open FileName:="d:\Test\test.txt", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
End Sub
-
April 24th, 2002, 10:37 AM
#2
Re: variable vs "text"; How can I put the variable of "xxx" instead of "xxx", if "xxx" must be "xxx"
i think this should do the thrick:
w.Documents.Open FileName=SelectedFile, ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
The fault is in the filling of selectedfile. You have to fill it like this:
selectedfile = Dir1.Path & "\" & File1.FileName
Dir1.path shows the fullpathname of the directory Dir1 is standing in.
The &-sign is to attach two strings together
File1.filename is the filename you have selected.
-
April 24th, 2002, 06:35 PM
#3
I still have Type mistmatch error. Please once more!
Hi,
I am not sure if I assigned a whole path to SelectedFile incorrectly, or I should not have used SelectedFile in place of "D:\..."
Thank you.
-
April 25th, 2002, 01:43 AM
#4
Re: I still have Type mistmatch error. Please once more!
I don't know what could be wrong, but what you could do is add this line bevore you open the wordfile:
msgbox selectedfile, this way you can see if there is something wrong with selectedfile.
But i think the problem will be in one of the other parameters. When i open a word document i do it like this:
Dim X as Object
set X = CreateObject("Word.application")
X.Visible = false
X.Documents.Open FileName:=selectedfile 'make sure that the extention of the file is .doc
X.ActiveDocument.SaveAs FileName:=selectedfile 'if you want to save the file
X.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
X.Quit
set X = nothing
I hope this answers your question
-
April 25th, 2002, 04:06 AM
#5
It works. Thank you for your advices.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|