Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-25-2011, 01:50 PM
Lu_Argentina Lu_Argentina is offline Windows 98/ME Office 2007
Novice
 
Join Date: Oct 2010
Posts: 3
Lu_Argentina is on a distinguished road
Default VBA to open files in Word

Hi! I have many html files that I want to open and copy its content in another document. The files are consecutive so I would like to write a macro that loops through them, open copy and close.
I have saved a macro and the code is:
Code:
Documents.Open FileName:="page_4.html", ConfirmConversions:=False, _
  ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
  PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
  WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=47, Extend:=wdExtend
Selection.Copy
Windows("Documento2").Activate
Windows("page_4").Activate
ActiveWindow.Close
the file that increases consecutively is page_4.html so I guess I need some for... and a way to name the file.
Thanks!!!

Last edited by macropod; 07-25-2011 at 11:44 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 07-26-2011, 12:04 AM
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 9,830
macropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the rough
Default

Hi Lu Argentina,

Looping through a set of files, opeing & closing them is reasonably straightforward. See the code I posted here: http://www.msofficeforums.com/vba/82...documents.html
However, your code suggests you're not copying the whole document and it gives no indication of where in 'Documento2' the copied material is to be inserted. You need to clarify those issues.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 07-26-2011, 07:21 AM
Lu_Argentina Lu_Argentina is offline Windows 98/ME Office 2007
Novice
 
Join Date: Oct 2010
Posts: 3
Lu_Argentina is on a distinguished road
Default

Hi Macropod, thanks for your answer.
You're right I haven't write that part of the problem. I want to open the htlm file, copy its content and the paste it in document 2 under the last line. As I've said, they are consecutive files so I need to do this in certain order.
The size of the htlm file is always the same, so I guess that shouldn't be a problem.
I have read your code but I can't figure out how this could help me. Could you please explain me a little bit more? thanks a lot!
cheers, Luciana
Reply With Quote
  #4  
Old 07-26-2011, 05:47 PM
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 9,830
macropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the rough
Default

Hi Luciana,

The code in the link goes through all the .doc files in a folder chosen by the user, processes them, then saves the output to another folder.

For your purposes, the requirements are similar, except that the processing consists of copying content from the opened html files to another file. the requirement to process the files in a particular order does potentially complicate things - it all depends on whether the order they'd be opened in by default matches your required order.

Note: I'm unable to provide much further help, as I'm about to head off some extended travelling and will be out of contact.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Files don't open correctly jcgtc Office 0 05-09-2010 05:56 AM
cant open .htm files from inbox jamesukm Outlook 0 02-01-2010 04:27 AM
saving all open files reverter Word 5 01-28-2010 02:02 PM
unable to open *.tif files HARIS Misc 1 12-01-2009 04:47 AM
Can't open .pst legacy files RetiredEngineer Outlook 1 11-14-2009 12:06 PM


All times are GMT -7. The time now is 09:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft