Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 20th, 2007, 10:48 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old November 20th, 2007, 08:51 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
  #3 (permalink)  
Old November 21st, 2007, 09:50 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
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:)

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.