Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Strings vs documents (as variables) (WinNT/Word97)

    Just a quick question (I hope) but I can't work it out.

    I have two variables in a module; strFilePT and docFilePT - the first dimmed as a string, the second as a document. I have the following code which I hope would pass the document path and name in the string variable to the document variable:

    strFilePT = strSrchPath + "" + strFileSpec
    set docFilePT = strFilePT

    However, when I debug this it says 'type mismatch'; without the 'set' it says 'invalid use of property'.

    What am I doing wrong, please?

    Many thanks in advance!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    A document is an object, not a string. Do you want to open the document whose full path is in strFilePT? If so, you can use

    Set docFilePT = Documents.Open(strFilePT)

    Or do you want something else? If so, please explain.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    Sorry, Hans - what I need to do is change the attached template on every file ending with .doc within a tree of folders. I don't mind whether I open them or not, but I've a feeling I'm going to have to since this is part of the job I've been working on in XL for which I need to have a Word shell ('Run Word thru XL?'), and that macro said it couldn't change it because it's a 'read-only' property.

    Hence the need to write something in Word that will change them all in one go so I don't need to include it in the XL part!

    <small>I was trying to avoid having to ask how to do the job, but as usual I got stuck again ... <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15><small>
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    You'll have to open each document in turn, set the AttachedTemplate property, then close & save the document. There is no way to change the attached template without opening the document.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    Hans, I'm sorry, but I just can't get this to work! All I want to do is, as I said, cycle through every Word document in a directory, including sub-directories, and set the attached template on each one. This is as far as I've got (there's probably quite a bit of extraneous code in there - as I said, I was trying to cannibalise some old code that jscher helped me with a long time ago!):

    <pre>Sub FindDocsAndChangeAttachedTemplate()
    Dim FSO As FileSearch, strSrchPath As String, strFileSpec As String
    Dim FC As Folder, docFilePT As Document, strFilePT As String
    Dim strCategory As String

    'customize in code and/or elicit from user
    strSrchPath = InputBox("Give path of directory to search", , "p:documentation")
    strFileSpec = "*.doc"
    inputCategory:
    On Error GoTo emptyString
    On Error GoTo 0

    'conduct search and post results in blank doc
    Set FSO = Application.FileSearch
    With FSO
    .NewSearch
    .LookIn = strSrchPath
    .SearchSubFolders = True
    .FileName = strFileSpec
    .MatchAllWordForms = False
    .FileType = msoFileTypeWordDocuments
    strFilePT = strSrchPath + "" + strFileSpec
    Set docFilePT = Documents.Open(strFilePT)

    If .Execute() > 0 Then
    With docFilePT
    .AttachedTemplate = "t:itprocnew.dot"
    .Save 'noprompt:=True, OriginalFormat:=wdOriginalDocumentFormat
    .Close
    End With
    Else
    MsgBox "Nothing found"
    GoTo dumpObj
    End If
    End With

    dumpObj:
    Set FSO = Nothing
    Exit Sub

    emptyString:
    If MsgBox("Don't you want to open some documents?", vbCritical + vbYesNo) _
    <> vbYes Then Exit Sub
    Resume inputCategory

    End Sub
    </pre>


    I would be extremely grateful if you would assist!
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    Does the attached code do what you want?

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Strings vs documents (as variables) (WinNT/Word97)

    Thank you, Hans, yes, it does exactly that. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    I don't know what I'd do if it weren't for everyone at the Lounge! (panic, probably ...)

    Muchos gracias!
    Beryl M


Posting Permissions

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