Results 1 to 2 of 2

Thread: VB Macro help

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    VB Macro help

    I was wondering if someone could help me tweak this code a little. This a macro in word that should save the document as a txt file with current filename that it has. The code below is saving all of the files into one notepad file called wrkord. Basically the word document gets open through a program and it gets assigned a number like (R792384750943875.rtf) When the user saves the document it saves it to a folder on the network where another program picks it up. All files should be separate, not all lumped together like they are now. THANKS

    VB Code:
    1. Public Sub HMSSave(Optional informUser As Boolean = True)
    2.  
    3. 'variables added for brit
    4. Dim wpathdoc As String
    5. Dim wpathtx As String
    6. Dim docToClose As String
    7. Dim docToClose As String
    8. Dim foundstring As Long
    9. Dim britpathtxt As String
    10. Dim tempvar As String
    11. 'end of variables
    12.  
    13. 'save a version for brit teleradiology
    14. If ActiveDocument.Name Like "*_temp.doc" Then
    15. System.Cursor = wdCursorWait
    16. wpathdoc = ActiveDocument.Variables("wpathdocvar").Value
    17. wpathtxt = ActiveDocument.Variables("wpathtxtvar").Value
    18.  
    19. foundstring = InStr(1, wpathtxt, "\")
    20. tempvar = wpathtxt
    21. While foundstring <> 0
    22. tempvar = Mid(tempvar, foundstring + 1)
    23. foundstring = InStr(foundstring, tempvar, "\")
    24. Wend
    25. 'end of brit code
    26.  
    27. ActiveDocument.save 'saves the doc as "app_path + \temp.doc"
    28. On Error Resume Next
    29. Kill wpathdoc
    30. Kill wpathtxt
    31.  
    32. ' New for brit
    33. Kill britpathtxt
    34. ' End
    35.  
    36. On Error GoTo 0
    37. ' store the name of the current document
    38. docToOpen = ActiveDocument.FullName
    39. ' createtextfile (APP_PATH + "\temp.txt")
    40. ActiveDocument.SaveAs FileName:=wpathtxt, fileformat:=wdFormatDOSTextLineBreaks
    41. 'Save a txt copy for brit teleradiology
    42. britpathtxt = "I:\brit\" & ActiveDocument.Name
    43. ActiveDocument.SaveAs fileName:=britpathtxt, fileformat:=wdFormatDOSTextLineBreaks
    44. 'end
    45. 'get the current name of the doc
    46. docToClose = ActiveDocument.Name
    47. 're-open temp.doc for more editing
    48. Documents.Open docToOpen
    49. 'Close the other doc
    50. Document(docToClose).Close
    51.  
    52. If informUser = true then
    53. MsgBox “Document saved.”, vbOKOnly + vbInformation, “HMS Trans”
    54. End if
    55. =============================================================This is the new code that they have in the Macro
    56.  
    57. Public Sub HMSSave(Optional informUser As Boolean = True)
    58. shouldBeMoved = True
    59. 'Make sure to update all built in document properties.
    60. ActiveDocument.ComputeStatistics wdStatisticCharacters
    61. ActiveDocument.ComputeStatistics wdStatisticCharactersWithSpaces
    62. ActiveDocument.ComputeStatistics wdStatisticLines
    63. ActiveDocument.ComputeStatistics wdStatisticPages
    64. ActiveDocument.ComputeStatistics wdStatisticWords
    65.  
    66. ActiveDocument.save
    67.  
    68. If informUser = True Then
    69. If getType() = TYPE_DOCUMENT Then
    70. VBA.MsgBox "Transcription document saved.", vbOKOnly + vbInformation, "HMS Transcription"
    71. Else
    72. VBA.MsgBox "Transcription template saved.", vbOKOnly + vbInformation, "HMS Transcription"
    73. End If
    74. End If
    75.  
    76. End Sub
    Last edited by Jnickrand; Aug 30th, 2005 at 07:49 AM.

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