CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2002
    Location
    Seoul, the capital of the universe.
    Posts
    63

    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


  2. #2
    Join Date
    May 2000
    Location
    Belgium, Bruges
    Posts
    146

    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.


  3. #3
    Join Date
    Feb 2002
    Location
    Seoul, the capital of the universe.
    Posts
    63

    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.


  4. #4
    Join Date
    May 2000
    Location
    Belgium, Bruges
    Posts
    146

    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



  5. #5
    Join Date
    Feb 2002
    Location
    Seoul, the capital of the universe.
    Posts
    63

    It works. Thank you for your advices.

    Have a nice day.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured