Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Word Macro To Modify Files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2648
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Word Macro To Modify Files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Word Macro To Modify Files - 4/11/2005 9:15:26 PM   
  Teignmouth2005

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
Hi all, I was hoping somebody on here might be able to help me with a query regarding a macro I've been writing for my organisation.

The piece of script in question is designed to make formatting modifications to a file which I can successfully do. At presentm, the script (which is copied below) asks the user for the file number/name they wish to modify, they type this in, the file is loaded, changed and saved. However, the aim is to be able to run this script of a batch of maybe a dozen or so files automatically, rather than have to prompt the user each time for the file name.

Any suggestions on how to get the script to open all files in a specified location (ie. C:\files\) and make the changes rather than needing to enter the file name. The actual files will differ on a daily basis and have randomly generated file names.

Many thanks for any help you can provide.

Darren Hermes

**** Script as it stands at present in the MS Word macro ****

Sub ChangeText()

Dim strData as String
strData = InputBox("What file number?")

Documents.Open FileName:= strDATA & ".txt"

Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=7, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=48
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeText Text:=" "
Selection.HomeKey Unit:=wdLine

ActiveDocument.Save

End Sub
 
 
Post #: 1
 
 Re: Word Macro To Modify Files - 4/12/2005 6:24:09 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I'm not familiar with Word Macro, but the following code in VBS will get a list of files from a pre-defined directory. Perhaps you can find ways to integrate it into your script.

=====================================================================
src = "C:\temp"
set fso = createobject("scripting.filesystemobject")
for each file in fso.getfolder(src).files
wscript.echo file
next

(in reply to Teignmouth2005)
 
 
Post #: 2
 
 Re: Word Macro To Modify Files - 4/13/2005 1:44:27 AM   
  Teignmouth2005

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
Excellent, thanks for that, I'll give it a go.

(in reply to Teignmouth2005)
 
 
Post #: 3
 
 Re: Word Macro To Modify Files - 4/13/2005 7:24:41 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
No problem, wish I could do more though :\

(in reply to Teignmouth2005)
 
 
Post #: 4
 
 Re: Word Macro To Modify Files - 4/13/2005 10:28:19 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
I have something similar...

I do file mods on very different files, only the mods are all the same... What i did is:

Create a macro in my Normal.dot...Create an external VBS which calls the desired file(s) and runs the Macro (all from the same VBS, which i only need to fire up: the .vbs)

Easy does it...

(in reply to Teignmouth2005)
 
 
Post #: 5
 
 Re: Word Macro To Modify Files - 4/19/2005 3:11:52 AM   
  Teignmouth2005

 

Posts: 4
Score: 0
Joined: 4/11/2005
From:
Status: offline
Snipah - do you have any example code of how you did this please?

Most appreciated.

(in reply to Teignmouth2005)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Word Macro To Modify Files Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts