PDA

View Full Version : Saving document to specific location



ooohhhnin
09-28-2010, 10:46 PM
Is there any way to automate saving of file to specific location based on a word or phrase in the file?

On my main folder, there are 5 subfolders:

C:\Mainfolder\AAA
C:\Mainfolder\BBB
C:\Mainfolder\CCC
C:\Mainfolder\DDD
C:\Mainfolder\EEE

I wanted to automate saving of file based on a specific word in the file (example: file contains "AAA", thus the file should be saved to C:\Mainfolder\AAA

I am hoping someone would help here. thank you

fumei
09-29-2010, 09:42 AM
Yes it can be done. Find the word. Use the word in a File SaveAs operation.
[vba]
If Instr(ActiveDocument.Content, "AAA") > 0 Then
ActiveDocument.SaveAs Filename:="C:\Mainfolder\AAA\" & _
whatever you are using for a filename
End If
[/code]

fumei
09-29-2010, 10:01 AM
Yes it can be done. Test if the word is in the document. Use the word in a File SaveAs operation.

If Instr(ActiveDocument.Content, "AAA") > 0 Then
ActiveDocument.SaveAs Filename:="C:\Mainfolder\AAA\" & _
whatever you are using for a filename
End If
Fully, to cover all your possible strings, use ElseIf (as much as i dislike to use ElseIf).
Public CONST Main As String = "C:\Mainfolder\"

Sub Yadda()
If Instr(ActiveDocument.Content, "AAA") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "AAA\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "BBB") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "BBB\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "CCC") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "CCC\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "DDD") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "DDD\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "EEE") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "EEE\" & _
whatever you are using for a filename
End If

ooohhhnin
09-29-2010, 08:08 PM
Yes it can be done. Test if the word is in the document. Use the word in a File SaveAs operation.

If Instr(ActiveDocument.Content, "AAA") > 0 Then
ActiveDocument.SaveAs Filename:="C:\Mainfolder\AAA\" & _
whatever you are using for a filename
End If
Fully, to cover all your possible strings, use ElseIf (as much as i dislike to use ElseIf).
Public CONST Main As String = "C:\Mainfolder\"

Sub Yadda()
If Instr(ActiveDocument.Content, "AAA") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "AAA\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "BBB") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "BBB\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "CCC") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "CCC\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "DDD") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "DDD\" & _
whatever you are using for a filename
Else If Instr(ActiveDocument.Content, "EEE") > 0 Then
ActiveDocument.SaveAs Filename:= Main & "EEE\" & _
whatever you are using for a filename
End If


Thank you fumei for this. However, I forgot to state some details:

The text I stated should be found on a specfic location on the document (the text should be found on the footer). Is this possible that macro should looking on the footer only?

ooohhhnin
09-29-2010, 09:02 PM
Also, the text should be case sensitive.
Can the filename also be retain as its original filename? I'm actually retrieving the document on a folder and the the file has already been saved?