#1
|
|||
|
|||
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 Thanks!!! Last edited by macropod; 07-25-2011 at 11:44 PM. Reason: Added code tags |
#2
|
||||
|
||||
Hi Lu Argentina,
Looping through a set of files, opeing & closing them is reasonably straightforward. See the code I posted here: https://www.msofficeforums.com/vba/8...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 [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Can I repoen this thread?
|
#6
|
||||
|
||||
Kindly start a new thread.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
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 05:27 AM |
saving all open files | reverter | Word | 5 | 01-28-2010 03:02 PM |
unable to open *.tif files | HARIS | Misc | 1 | 12-01-2009 05:47 AM |
Can't open .pst legacy files | RetiredEngineer | Outlook | 1 | 11-14-2009 01:06 PM |