|
-
Aug 26th, 2005, 08:03 AM
#1
Thread Starter
Junior Member
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:
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
'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
ActiveDocument.save 'saves the doc as "app_path + \temp.doc"
On Error Resume Next
Kill wpathdoc
Kill wpathtxt
' New for brit
Kill britpathtxt
' End
On Error GoTo 0
' store the name of the current document
docToOpen = ActiveDocument.FullName
' createtextfile (APP_PATH + "\temp.txt")
ActiveDocument.SaveAs FileName:=wpathtxt, fileformat:=wdFormatDOSTextLineBreaks
'Save a txt copy for brit teleradiology
britpathtxt = "I:\brit\" & ActiveDocument.Name
'end
'get the current name of the doc
docToClose = ActiveDocument.Name
're-open temp.doc for more editing
Documents.Open docToOpen
'Close the other doc
Document(docToClose).Close
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
'Make sure to update all built in document properties.
ActiveDocument.ComputeStatistics wdStatisticCharacters
ActiveDocument.ComputeStatistics wdStatisticCharactersWithSpaces
ActiveDocument.ComputeStatistics wdStatisticLines
ActiveDocument.ComputeStatistics wdStatisticPages
ActiveDocument.ComputeStatistics wdStatisticWords
ActiveDocument.save
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
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.
-
Aug 26th, 2005, 08:06 AM
#2
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
-
Aug 26th, 2005, 09:07 AM
#3
Thread Starter
Junior Member
Re: New program broke our code
-
Aug 26th, 2005, 09:11 AM
#4
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?
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...
-
Aug 26th, 2005, 09:15 AM
#5
Thread Starter
Junior Member
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).
-
Aug 26th, 2005, 09:33 AM
#6
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?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|