Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2007, 10:48 AM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I Delete a MS Word Table using visual basic

Hi,

I'm a complete novice with VB, so please go easy with me... :)

I have a MS Word document with two tables in it. I have 2 command buttons in it. When the user presses command button 1, I want TABLE 2 to be deleted. When the user presses command button 2, I want TABLE 1 to be deleted. Hope this makes sense... :)

In short I would like some advice on the script required to DELETE A MS WORD TABLE when a command button is pressed, utilising VBA.

Can anyone help me, or suggest an alternative way of achieving this?

Many thanks for your anticipated help and advice :D


 
Old November 20th, 2007, 08:51 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi here is the code to delete a table

Sub Delete_Table()

Dim oWD As Word.Document

Set oWD = ActiveDocument

If oWD.Tables.Count <> 0 Then
    oWD.Tables(1).Delete
End If

End Sub

A small warning : When you delete the Table 1, your Table 2 becomes Table 1. You need to handle this in the code, either by using some document variables or by using some bookmarks. This will ensure that the intended actions happen

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old November 21st, 2007, 09:50 AM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks for the help and advice. I'll be trying it out this afternoon and will let you know how I get on.

Thanks for your help again! :D:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Ms Access report to MS Word doc kite Access 1 October 22nd, 2007 01:45 AM
Linked Table Manager path in Visual Basic AstridVM BOOK: Access 2003 VBA Programmer's Reference 3 December 29th, 2006 10:34 AM
MS Access ----> MS Word anukagni Access 1 August 30th, 2006 02:15 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM
How to use MS Office Assistants from Visual Basic Chandu1506 VB How-To 1 April 22nd, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.