Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 06-19-2018, 08:23 PM
gmayor's Avatar
gmayor gmayor is offline Applying bookmarks to multiple documents - is it possible? Windows 10 Applying bookmarks to multiple documents - is it possible? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by klutch View Post
I am getting an ActiveX can't create object error on this line
Code:
Set wdApp = GetObject(, "Word.Application")
Sorry. I missed the reference that you were using the Mac version . However the part of the code that references the table and its cells should still be valid for insertion into your original macro.


As for which table, you can select the table by its number i.e. in the code wdDoc.Tables(1) 1 refers to the first table.


If the table in question varies according to the data then you will have to describe how the table to be processed is determined.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



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 11:46 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