问题
Below are two sets of VBA code that deletes text boxes, the first one works in MS Excel and the second in MS Word. The only difference between the two is the third line after "Active".
I'm trying to duplicate this action in MS Outlook in a new-opened email but lack the knowledge of the proper code terminology... is there anyone out there that knows the answer to this?... thank you,.
Sub RemoveTextBox()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoTextBox Then shp.Delete
Next shp
End Sub
Sub RemoveTextBox()
Dim shp As Shape
For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then shp.Delete
Next shp
End Sub
回答1:
For Outlook it will look like the following Example
Option Explicit
Public Sub Example()
Dim Inspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim Shp As Word.Shape
Set Inspector = Application.ActiveInspector()
Set wdDoc = Inspector.WordEditor
For Each Shp In wdDoc.Shapes
Debug.Print Shp.Type 'msoTextBox = 17 - Print on Immediate Window
If Shp.Type = msoTextBox Then Shp.Delete
Next
End Sub
For open email work with Application.ActiveInspector Method (Outlook) and Inspector.WordEditor Property (Outlook)
Inspector.WordEditor Property (Outlook) Returns the Microsoft Word Document Object Model of the message being displayed. Read-only, The WordEditor property is only valid if the IsWordMail method returns True and the EditorType property is olEditorWord. The returned WordDocument object provides access to most of the Word object model except for the following members:
Application.ActiveInspector Method (Outlook) Returns the topmost Inspector object on the desktop.
Remember to add reference to word xx object library
1. From the Tools menu, choose References to display the References dialog box.
2. The References dialog box shows all object libraries registered with the operating system. Scroll through the list for the application whose object library you want to reference. If the application isn't listed, you can use the Browse button to search for object libraries (.olb and .tlb) or executable files (.exe and .dll on Windows). References whose check boxes are checked are used by your project; those that aren't checked are not used, but can be added.
来源:https://stackoverflow.com/questions/44054466/text-box-in-outlook-email