Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Macro - Documents.Open fileName:= Need help with this command


Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2005, 10:51 AM
psxChelly psxChelly is offline
Newcomer
 
Join Date: Apr 2005
Posts: 2
Default Macro - Documents.Open fileName:= Need help with this command


Hello. I am trying to have a macro open about 300 files that are similarly named in the same directory, to add 3 lines of data. the " * " doesnt seem to work. I am new to making macros and would appreciate any help.

I need help with this line:
Documents.Open fileName:=" .tfw"


this is what i have so far.
Code:
Sub FindReplace() ' ' OpenAdd Macro ' ChangeFileOpenDirectory "C:\alcatraz\04282005_imagery\" Documents.Open fileName:=" .tfw", ConfirmConversions:=False, _ ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _ PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _ WritePasswordTemplate:="", Format:=wdOpenFormatAuto, Encoding:=1252 Selection.MoveDown Unit:=wdLine, Count:=5 Selection.EndKey Unit:=wdLine Selection.TypeParagraph Selection.TypeText Text:="10" Selection.TypeParagraph Selection.TypeText Text:="5000" Selection.TypeParagraph Selection.TypeText Text:="5000" ActiveDocument.Save ActiveDocument.Close End Sub
Edit by moderator: You can use [vb][/vb] tags to format your code. Click 'Reply' on this post to see how tags work.

Last edited by herilane; 04-29-2005 at 02:47 PM.
Reply With Quote
  #2  
Old 04-29-2005, 02:51 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Welcome to the forum.

Files need to be opened one by one, you cannot use wildcards like * with Documents.Open. What you need is a loop. You can use Dir() in a loop to get the names of all files in a folder.

You say you're new to macros - exactly how new? Are you familiar with using variables and loops and such? I can post you a simple example, but don't know what level of detail you need.
Reply With Quote
  #3  
Old 05-02-2005, 07:03 AM
psxChelly psxChelly is offline
Newcomer
 
Join Date: Apr 2005
Posts: 2
Default

thanks for answering. I used to use them about 5 years ago and havent since. I consider myself a newbie again. out of sight out of mind you know.

any help is appreciated.
michelle


Quote:
Originally Posted by herilane
Welcome to the forum.

Files need to be opened one by one, you cannot use wildcards like * with Documents.Open. What you need is a loop. You can use Dir() in a loop to get the names of all files in a folder.

You say you're new to macros - exactly how new? Are you familiar with using variables and loops and such? I can post you a simple example, but don't know what level of detail you need.
Reply With Quote
  #4  
Old 05-02-2005, 10:33 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

OK.

I would do this in two steps. First, get a list of all files. Second, process the list of files.

For step one, the basic approach would be like this:
Code:
Dim strFile As String strFile = Dir$("c:\temp\*.doc") 'Get first item in folder Do While strFile <> "" 'If something was found... Debug.Print strFile '... do something with it... strFile = Dir$() '... and get the name of the next file Loop
For putting the data in an array, look up the following help topics in Word VBA help: Using Arrays and Redim Statement.

For going through the array that you have, look up Using For...Next Statements.
Code:
Dim strMyFiles() As String Dim i As Integer 'Fill the array 'Now use the array to open files: For i = LBound(strMyFiles) To UBound(strMyFiles) Documents.Open "C:\temp\" & strMyFiles(i) Next i
Hope this gets you started.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->