Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Is In Use (VB6)

    I changed the following code from a network drive to work in the local drive C:
    Since changing this, I'm getting a prompt saying the file is in use by another application or user.

    Microsoft advise to save the template before closing, but this does not work.
    I also tried setting oDoc.Close True, to no avail.

    <pre> Dim JN As String
    Dim oWord As Object
    Dim oDoc As Object

    Me.MousePointer = vbHourglass

    ' Start Word
    Set oWord = CreateObject("Word.Application")

    ' Create document based on template
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesHeader.dot")
    ' Import report
    oWord.Selection.InsertFile "C:Inv.doc", , False
    ' Process document
    With oWord.Selection.Find
    .Execute "^p^p^p^p^p^wInvoice", , , , , , , 1, , _
    "^m INVOICE", 2
    .Execute Chr(26), , , , , , , 1, , "", 2
    .Execute "^p^p^p^p", , , , , , , 1, , "", 2
    End With

    ' Save and close the document
    oDoc.Protect 2, , "Password"

    JN = InputBox("Please Enter A Reference Number For Your Document", "")

    oDoc.SaveAs "C:MM-UtilitiesM&M Invoice" & " " & JN & ".doc"
    oDoc.Close True
    Set oDoc = Nothing
    oWord.NormalTemplate.Saved = True
    oWord.Quit
    Set oWord = Nothing</pre>


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

    Re: File Is In Use (VB6)

    Dave,

    In the line beginning with oDoc.SaveAs you already save the document. Saving it again in the next line is not going to help. By the way, setting oWord.NormalTemplate.Saved = True does not save the template, it tells Word that the template has already been saved, so that it need not prompt you to save it.

    Perhaps one of the temporary files that Word creates was left behind. Open the folder C:MM-Utilities in Windows Explorer, and look for files whose name start with ~$. They are used by Word to keep track of who has a document open.
    Note: these files have the Hidden bit set; to see them, make sure that "Show hidden files and folders" has been selected in the View tab of Tools | Folder Options...

    If you see any such files, delete them.

    Also, locate your Normal.dot. In Windows XP, it will be in Cocuments and Settings<username>Application DataMicrosoftTemplates. Delete files starting with ~$ there too.

    It might also be a good idea to quit all open applications, except for Windows Explorer, and clear your Temp folder. In Windows XP, it is probably Cocuments and Settings<username>Local SettingsTemp.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    Hans

    The only ~$.............. files I found were in the recycle bin.
    The problem seems to have stopped, and have also commented the NormalTemplate.Saved line out also.

    <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    Hans
    I know I've stretched this subject, way beyond where help is available, but this formatting is so confusing.
    I think maybe because I don't understand how to read the original text (Inv.doc) and how to determine where the page breaks, tabs etc are.

    I've printed Marcs Character codes (Thanks Marc) but they are not helping me.

    With using the formatting code ie, ^p^p ^m etc, I just can't get the hang of it.
    If the "ESTIMATE" will fit on one page, the format is ok, but where it has to continue onto another page, the spacing is incorrect.

    I played about with it and checked the help file and ended up with 5 pages which should only have been 2.

    I've got it back to 2 pages but the "Labour figure" Is a pain staying in the left of the page:

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    ..

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

    Re: File Is In Use (VB6)

    <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23> And now you're a SilverLounger! <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23>

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    Silver Lounger !!

    I think Brain Dead's my current status at the moment !
    Never mind, I can have a couple of beers tonight <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>

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

    Re: File Is In Use (VB6)

    Do you think the <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> will improve your brain cells? <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    I am looking at your file, but it will take some time.

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    No but <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> will <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

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

    Re: File Is In Use (VB6)

    Dave,

    Try this code. I don't know if it is possible to catch every possible situation, since the DOS reports seem to contain varying printer control codes, but this seems to do a reasonable job:
    <pre> Dim JN As String
    Dim oWord As Object
    Dim oDoc As Object

    Me.MousePointer = vbHourglass

    ' Start Word
    Set oWord = CreateObject("Word.Application")

    ' Create document based on template
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesHeader.dot")
    ' Import report
    oWord.Selection.InsertFile "C:Inv.doc", , False
    ' Process document
    With oWord.Selection.Find
    .Execute "^p^p^p^p^p^wInvoice", , , , , , , 1, , _
    "^m INVOICE", 2
    .Execute "^p^p^p^p^p^wEstimate", , , , , , , 1, , _
    "^m ESTIMATE", 2
    .Execute Chr(26), , , , , , , 1, , "", 2
    Do While .Execute(Chr(27), , , , , , , 1) = True
    oWord.Selection.HomeKey , 1
    oWord.Selection.EndKey , 1
    oWord.Selection.Delete
    Loop
    .Execute "^w^p", , , , , , , 1, , "^p", 2
    Do While .Execute("^p^p^p", , , , , , , 1, , "^p", 2) = True
    Loop
    .Execute "

  11. #11
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: File Is In Use (VB6)

    > Note: the "

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    Hans
    Yes DOS spits out the doc in different variations, it depends how much is on the estimate ie amount of operations.
    An estimate can have just a couple of items to repair the car or it can have 40,50 items, dependent on severety of damage.

    Your code works great, I have modified it slightly as I saw you were still referring to "Inv.Doc"
    (Were you trying to make the code global for both docs ie "Inv.doc", "Est.doc" ??)
    I've also added code to delete the doc once it has been E:Mailed, it's not required to be saved once it's gone.

    I think it's ok, at least the printout looks to be all in line.
    I've included the code in the post, just in case you see something un-toward.
    albeit I will test this with a couple of outputs to see the result.

    Regardless of whether it holds up, I thank you once again. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

    (Thanks Stuart for pointing out the oe ? character, )

    <pre>Private Sub procSWEstimate_Click(Index As Integer)
    Dim fso As FileSystemObject
    Dim JN As String
    Dim oWord As Object
    Dim oDoc As Object

    Me.MousePointer = vbHourglass

    ' Start Word
    Set oWord = CreateObject("Word.Application")

    ' Create document based on template
    Set oDoc = oWord.Documents.Add("C:MM-UtilitiesLeekHeader.dot")
    ' Import report
    oWord.selection.InsertFile "C:Est.doc", , False
    ' Process document
    With oWord.selection.Find
    .execute "^p^p^p^p^p^wEstimate", , , , , , , 1, , _
    "^m ESTIMATE", 2

    .execute Chr(26), , , , , , , 1, , "", 2
    Do While .execute(Chr(27), , , , , , , 1) = True
    oWord.selection.homekey , 1 ' << Not sure this executes
    oWord.selection.endkey , 1
    oWord.selection.Delete
    Loop
    .execute "^w^p", , , , , , , 1, , "^p", 2
    Do While .execute("^p^p^p", , , , , , , 1, , "^p", 2) = True
    Loop
    .execute [b]"

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

    Re: File Is In Use (VB6)

    Dave,

    I tried to make the code work for both invoices and estimates, that's why it contains a line for each.

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

    Re: File Is In Use (VB6)

    Stuart,

    Although my browser is set to use Times New Roman and Courier New as default fonts, it seems that text between <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags is displayed in the Courier font. I have a fairly standard Windows XP installation.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Is In Use (VB6)

    Hans

    With the different formats of the DOS outputs, would it be easier to strip out all the text and lay it over the .dot file.

    I could post all number of Estimates and Invoices but to cover every eventuality as you say would be both tiresum and probably impossible.

    I'm thinking if we strip all the text from the DOS doc (Inv.doc)(est.doc) or whatever doc, it would perhaps easier to create the new document from afresh.

    The code you supplied works great, but again, an Invoice and Estimate with only a few items, threw the format out again.

Page 1 of 2 12 LastLast

Posting Permissions

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