Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2011, 01:50 PM
Lu_Argentina Lu_Argentina is offline VBA to open files in Word Windows 98/ME VBA to open files in Word Office 2007
Novice
VBA to open files in Word
 
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's Avatar
macropod macropod is online now VBA to open files in Word Windows 7 64bit VBA to open files in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-26-2011, 07:21 AM
Lu_Argentina Lu_Argentina is offline VBA to open files in Word Windows 98/ME VBA to open files in Word Office 2007
Novice
VBA to open files in Word
 
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's Avatar
macropod macropod is online now VBA to open files in Word Windows 7 64bit VBA to open files in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-22-2022, 06:24 AM
firm firm is offline VBA to open files in Word Windows 10 VBA to open files in Word Office 2016
Novice
 
Join Date: Feb 2022
Posts: 2
firm is on a distinguished road
Default

Can I repoen this thread?
Reply With Quote
  #6  
Old 02-22-2022, 02:41 PM
macropod's Avatar
macropod macropod is online now VBA to open files in Word Windows 10 VBA to open files in Word Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Kindly start a new thread.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft