Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2015, 01:19 AM
Catty Catty is offline How to insert a table using bookmarks in a document Windows 7 32bit How to insert a table using bookmarks in a document Office 2010 32bit
Advanced Beginner
How to insert a table using bookmarks in a document
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default How to insert a table using bookmarks in a document

Hi,



I am trying to insert a table at a specific location in my document. Is there an easier way of doing this using bookmarks? Below is what I have been using and I keep getting a "Type Mismatch" error on the second line.

Code:
 Dim myRange As Range
    Set myRange = ActiveDocument.Range.Bookmarks("InsertDuty")
    ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=4
Reply With Quote
  #2  
Old 04-22-2015, 04:11 AM
gmayor's Avatar
gmayor gmayor is offline How to insert a table using bookmarks in a document Windows 7 64bit How to insert a table using bookmarks in a document Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

The second line should be
Code:
Set myRange = ActiveDocument.Range.Bookmarks("InsertDuty").Range
__________________
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
  #3  
Old 04-22-2015, 05:58 AM
gmaxey gmaxey is offline How to insert a table using bookmarks in a document Windows 7 32bit How to insert a table using bookmarks in a document Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Your code with Graham's revisions inserts a table "AT" a bookmark. If you want to "WRAP" the table "IN" the bookmark use:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range, oTbl As Word.Table
  Set oRng = ActiveDocument.Range.Bookmarks("InsertDuty").Range
  Set oTbl = ActiveDocument.Tables.Add(Range:=oRng, NumRows:=3, NumColumns:=4)
  ActiveDocument.Bookmarks.Add "InsertDuty", oTbl.Range
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 05-04-2015, 03:05 AM
Catty Catty is offline How to insert a table using bookmarks in a document Windows 7 32bit How to insert a table using bookmarks in a document Office 2010 32bit
Advanced Beginner
How to insert a table using bookmarks in a document
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Thank you all for your responses.

I was eventually able to get the macro to do what I wanted, albeit I think I took the long route to do it.

Below is what I used, but will definitely use your suggestions in the future...thanks again



Code:
Dim oTable As Table
Dim oCell As Cell
Dim oNewRow As Row

    'Go to InsertBookmark
        Selection.GoTo what:=wdGoToBookmark, Name:="InsertBookmark"
        
    'Insert table near bookmark
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1
    
    'identify table
    Set oTable = ActiveDocument.Tables(1)
    ' Insert new row
    Set oNewRow = oTable.Rows.Item(1)
    'identify the required cell in the new row
    Set oCell = oNewRow.Cells(1)        'the first cell in the row
   
    'insert/do whatever in the cell.....
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert a table using bookmarks in a document split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Insert table in document - automatically updates second table in summary? Mechanic Word 2 08-01-2012 09:44 PM
How to insert a table using bookmarks in a document Table of Bookmarks Niy Word 3 03-28-2012 12:18 AM
Insert image in bookmarks kroz Word VBA 0 11-29-2010 04:55 AM
Using bookmarks in a protected document Bill Stemp Word 0 10-16-2010 06:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:32 PM.


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