Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-19-2018, 06:15 AM
klutch klutch is offline Applying bookmarks to multiple documents - is it possible? Windows 7 32bit Applying bookmarks to multiple documents - is it possible? Office 2016 for Mac
Advanced Beginner
Applying bookmarks to multiple documents - is it possible?
 
Join Date: Jun 2018
Posts: 31
klutch is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Assuming your bookmarks d5, d20 & D22 refer to the column and row of the word table then also assuming that the value of 'i' is correctly resolved (we don't have your sheet to test) then the following should work . Depending on what is in Range("E" & i) you don't have to select and copy it. Just write its content to the Word table.


The code uses late binding to Word and so does not need a reference to Word.



Code:
Sub CopyAndPaste()
Dim myfile, wdApp As Object, wdDoc As Object
Dim oRng As Object
Dim i As Integer, iRow As Integer
    'select truck report file
    ChDrive "E:\"
    ChDir "E:\WG\TVAL\"
 
    myfile = Application.GetOpenFilename(, , "Browse for Document")
    'searches for row with "avg" then selects column E(avg of temperature mean) of that row.
    i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
    'copies the cell - not necessary if you simply write the range
    Range("E" & i).Copy
 
    Set wdApp = GetObject(, "Word.Application")
    If Err Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open(myfile)
    iRow = Range("c2")
    If iRow < 0 Then iRow = Range("c2") * -1
    Set oRng = wdDoc.Tables(1).Cell(iRow, 5).Range
    oRng.End = oRng.End - 1
    oRng.Text = Range("E" & i)
    'or
    'oRng.Paste
End Sub
I am getting an ActiveX can't create object error on this line
Code:
Set wdApp = GetObject(, "Word.Application")
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having Issues Applying a Macro Across Multiple Files. Changes Just Don't Seem To Save. Kajex Word VBA 2 09-08-2017 06:37 AM
Applying heading style to multiple pages at once jane.bugai Word 5 02-24-2017 04:05 PM
Applying bookmarks to multiple documents - is it possible? Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Applying bookmarks to multiple documents - is it possible? Applying a conditional format to multiple rows secoo140 Excel 1 10-12-2013 07:19 PM
Publisher 2000 - Applying multiple styles Jerb Publisher 0 02-15-2009 10:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:30 AM.


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