Results 1 to 6 of 6

Thread: New program broke our code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    New program broke our code

    The problem that I am having is that a company came in and did some upgrades to our system. We some macros in Microsoft word that saved the file out to a folder on our network but with the new code it does not do that anymore. Could someone help me tweak the code so that it will save the file out to the network folder? (Thanks)

    Here is the code in our old macro that worked.
    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.     'end
    44.     'get the current name of the doc
    45.     docToClose = ActiveDocument.Name
    46.     're-open temp.doc for more editing
    47.     Documents.Open docToOpen
    48.     'Close the other doc
    49.     Document(docToClose).Close
    50.        
    51. If informUser = true then
    52. MsgBox “Document saved.”, vbOKOnly + vbInformation, “HMS Trans”
    53. End if  
    54. =============================================================This is the new code that they have in the Macro
    55.  
    56. Public Sub HMSSave(Optional informUser As Boolean = True)
    57.   shouldBeMoved = True
    58.   'Make sure to update all built in document properties.
    59.   ActiveDocument.ComputeStatistics wdStatisticCharacters
    60.   ActiveDocument.ComputeStatistics wdStatisticCharactersWithSpaces
    61.   ActiveDocument.ComputeStatistics wdStatisticLines
    62.   ActiveDocument.ComputeStatistics wdStatisticPages
    63.   ActiveDocument.ComputeStatistics wdStatisticWords
    64.  
    65.   ActiveDocument.save
    66.  
    67.   If informUser = True Then
    68.     If getType() = TYPE_DOCUMENT Then
    69.       VBA.MsgBox "Transcription document saved.", vbOKOnly + vbInformation, "HMS Transcription"
    70.     Else
    71.       VBA.MsgBox "Transcription template saved.", vbOKOnly + vbInformation, "HMS Transcription"
    72.     End If
    73.   End If
    74.  
    75. End Sub

    I added the old code to the first part of the new code and when I saved the document it saved without any errors. However it did not save a copy of the document to the network drive. Please help!!!!!!!! Thanks.





    Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
    Last edited by Hack; Aug 26th, 2005 at 08:14 AM.

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: New program broke our code

    Please add the [VBCODE] [/VBCODE] tags around your code please, this makes it easier on the eyes

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    Re: New program broke our code

    Sorry!!!!

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: New program broke our code

    Silly q's... but why do you not use the save-as bit of code you already had and make sure it goes to a default or specified path instead of assuming that app.path will be on the shared area.

    Hardcode a location or put the location in a text file to be read when saving...

    Their code does something? the stats bit? I just read the help file on it and it only returns stats, but their code doesn't do anything with it, so its pointless?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    Re: New program broke our code

    Well im not very good with VB so I had a hard time understanding what the old code actually doing. I just can't understand why it won't work now because I added the old code back into the new code (macro).

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: New program broke our code

    Code:
    Public Sub HMSSave(Optional informUser As Boolean = True)
      
        'variables added for brit 
        Dim wpathdoc As String
        Dim wpathtx As String
        Dim docToClose As String
        Dim docToClose As String
        Dim foundstring As Long
        Dim britpathtxt As String
        Dim tempvar As String
        'end of variables
    
    
    '---- Turn mouse to hourglass
    '---- get the doc path and the txt path
        
        'save a version for brit teleradiology
        If ActiveDocument.Name Like "*_temp.doc" Then
            System.Cursor = wdCursorWait
            wpathdoc = ActiveDocument.Variables("wpathdocvar").Value
            wpathtxt = ActiveDocument.Variables("wpathtxtvar").Value
                
            foundstring = InStr(1, wpathtxt, "\")
            tempvar = wpathtxt
            While foundstring <> 0
                tempvar = Mid(tempvar, foundstring + 1)
                foundstring = InStr(foundstring, tempvar, "\")
            Wend
        'end of brit code
     
    '---- /\ searches through the txt variable
    '---- for backslash - presumeably to get the path (last slash position)
    '---- you can do this in one line:
    '---- foundstring = instrrev(wpathtxt,"\")
        
    '---- save the active doc...
    '---- since you haven't specified a path then it must have been opened or copied n opened somewhere else. This just saves it.
    '---- the remarked bit would have saved it where-ever the application.path specified as a temp.doc
            ActiveDocument.save  'saves the doc as "app_path + \temp.doc"
        
    
    '---- ignores errors. If they happen, so what?
            On Error Resume Next
    
    '---- delete the doc and txt files 
    '---- and brit path... (wha..?)
            Kill wpathdoc
            Kill wpathtxt
        
        ' New for brit
            Kill britpathtxt
        ' End
        
    '---- reset the error catching - if it errors complain bitterly!
        On Error GoTo 0
    
    
    '---- grab the name of the current doc and save it as something else (ohhh the txt one!)
        ' store the name of the current document
        docToOpen = ActiveDocument.FullName
        ' createtextfile (APP_PATH + "\temp.txt")
        ActiveDocument.SaveAs FileName:=wpathtxt, fileformat:=wdFormatDOSTextLineBreaks
    
    '---- change the path to the brit place
    '---- but uh there is no saave anywhere here...
        'Save a txt copy for brit teleradiology
        britpathtxt = "I:\brit\" & ActiveDocument.Name
        'end
        'get the current name of the doc
        docToClose = ActiveDocument.Name
    
    '----open a specified doc and close this one
        're-open temp.doc for more editing
        Documents.Open docToOpen
        'Close the other doc
        Document(docToClose).Close
    
    '---- if you are meant to tell the user ... send up a message
    If informUser = true then
    MsgBox “Document saved.”, vbOKOnly + vbInformation, “HMS Trans”
    End if   
    
    
    '============================================================
    'This is the new code that they have in the Macro
    
    Public Sub HMSSave(Optional informUser As Boolean = True)
      shouldBeMoved = True
     
    '---- /\ declare a variable and set to true (slackers way)
    
    '---- \/ do a load of stats stuff that doesn't seem to save anywhere
     'Make sure to update all built in document properties.
      ActiveDocument.ComputeStatistics wdStatisticCharacters
      ActiveDocument.ComputeStatistics wdStatisticCharactersWithSpaces
      ActiveDocument.ComputeStatistics wdStatisticLines
      ActiveDocument.ComputeStatistics wdStatisticPages
      ActiveDocument.ComputeStatistics wdStatisticWords
    
    '---- save the doc (where-ever it was opened from
      ActiveDocument.save
      
    '---- if you need to notify the user, do so, and depending on the type, tell them that too
      If informUser = True Then
        If getType() = TYPE_DOCUMENT Then
          VBA.MsgBox "Transcription document saved.", vbOKOnly + vbInformation, "HMS Transcription"
        Else
          VBA.MsgBox "Transcription template saved.", vbOKOnly + vbInformation, "HMS Transcription"
        End If
      End If
    
    End Sub
    Does that help?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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