View Single Post
 
Old 06-08-2018, 08:05 AM
Plycc100no Plycc100no is offline Windows 10 Office 2013
Novice
 
Join Date: Jun 2018
Posts: 1
Plycc100no is on a distinguished road
Default Can I clear the contents of a table using VBA

Hi - I'm used to using VBA in excel but new to Word although I appreciate they should be similar.

My issue is that I have a word doc with VBA that sends the doc as an attachment through outlook. I've copied and pasted it but that bit seems to work ok.

The issue is that it is not sending through any amended contents (which I believe is due to the doc not being saved before emailed) so what I was going to do was add a line in to save the doc and then attach.

The doc contains two separate tables which I would like to know if I can clear the contents of 1 column in after the document is added to the email so I can save again in its original state.

ie
user completes tables and runs VBA
document saved
added to email
clears contents of table
document saves

I can't seem to work out how I would reference the 2 tables to clear the contents. In excel I would name a range etc but can't see how to do similar in Word.

My current code is

HTML Code:
Private Sub CommandButton1_Click()
Dim olkApp As Object
Dim strSubject As String
Dim strTo As String
Dim strBody As String
Dim strAtt As String
    strSubject = "Testing"
    strBody = "<p style='font-family:arial;font-size:12pt'>" & "Please see the attached document." & "</p>"
    strTo = xxxxxxxxx@xxxxxx.com
           
    strAtt = ActiveDocument.FullName
    
    Set olkApp = CreateObject("outlook.application")
    With olkApp.CreateItem(0)
        .OriginatorDeliveryReportRequested = True
        .To = strTo
        .Subject = strSubject
        .HTMLbody = strBody & vbCrLf & vbCrLf
        .attachments.Add strAtt
        '.send
        .Display
        
        
    End With
    
    ActiveDocument.Close _
 SaveChanges:=wdSaveChanges, _
 OriginalFormat:=wdOriginalDocumentFormat
    Set olkApp = Nothing
End Sub
As I say, this was "borrowed" from something else so any advice that could be given to improve etc would be gratefully received.
Reply With Quote