word-vba

Deleting CommandButtons by name in VBA Word 2010

微笑、不失礼 提交于 2019-12-13 18:24:54
问题 In a word template, I have two command buttons namely [Add section] which is named "CommandButton1" [Done] - which is named "CommandButton2" I need both buttons to be deleted at the click of [Done] Here's my code so far Private Sub CommandButton2_Click() Dim i As Integer For i = ThisDocument.InlineShapes.Count To 1 Step -1 With ThisDocument.InlineShapes(i) If .OLEFormat.Object.Name = "CommandButton1" Then .Delete End If End With Next End Sub The code is a combination of snippets I found

Word VBA: Moving textstring from the end of a paragraph to the beginning of the paragraph

£可爱£侵袭症+ 提交于 2019-12-13 12:34:09
问题 I'm new to VBA. I have several long documents where a citation or a document number appears at the end of a paragraph. Luckily, these citations and document are enclosed in parentheses, which should make it easy to isolate. I need to move the content of those parentheses (including the parentheses themselves) to the front of each paragraph and then add two spaces after the closing parenthesis. For example: This is my text in Paragraph 1. (http://nytimes.com) This is my text in Paragraph 2. (1

Convert hyperlink and bookmarked words to html <a> tag in Word using VBA macros

浪子不回头ぞ 提交于 2019-12-13 11:15:37
问题 I have a word with bookmarked like "click here". How should it be converted to HTML anchor tag using VBA macros <a href="https://stackoverflow.com/">click here</a> And then, if a word with bookmarked internal or external, how to convert the text, for e.g., a popup box appears on the word like "t20 CTRL+click to Link" <a href="t20">Introduction Matthew Davidson</a> 回答1: Actually, I would like to extract the hyperlinks from text. So I have solved the question with below the code. Sub

Find all text formatted with given color

橙三吉。 提交于 2019-12-13 11:13:27
问题 I am looking for a way to create a new document containing all the text with a specific format from my document. See below for what I wrote so far, but I'm stuck here: how do I stop my loop when end of document is reached? or how do I add intelligence to my code to avoid a static loop, and rather do a "scan all my document"? Option Explicit Sub Macro1() Dim objWord As Application Dim objDoc As Document Dim objSelection As Selection Dim mArray() As String Dim i As Long Dim doc As Word.Document

Removing the line where a content control is

﹥>﹥吖頭↗ 提交于 2019-12-13 09:47:58
问题 I want to remove a line where my content control is. Currently the document has this following text: t1 t2 Status: Draft Valid from: 01.01.2012 Valid for: All Emplyoees Created by: a Released by: <content control goes here>. I have a variable controlff which is a reference to the control. No matter how I get a range from it I always ended up by deleting the full text. This other questions didn't quite help me: Blank line after deleting contentControl in word How to remove the entire line of a

Why is range.find searching like this?

自古美人都是妖i 提交于 2019-12-13 09:46:52
问题 I am trying to search for occurrences of a particular string in a Word document. The code should search only after the Table of Contents. My completed code is below: Private Sub cmdFindNextAbbr_Click() Dim myRange As range 'CREATING DICTONARY for Selected Items If firstClickAbr = True Then txtNew = "" abSelIndex = 0 Set abSel = CreateObject("scripting.dictionary") Set abSelFirstStart = CreateObject("scripting.dictionary") firstClickAbr = False iAbbr = 0 For x = 0 To lstAbbreviations.ListCount

Word vba how to save picture from image object to file?

耗尽温柔 提交于 2019-12-13 07:50:06
问题 I have an image object on a userform. I want to save the picture from that image object into a file. I see many examples of how to load a picture into an image object, but none the other way around. I tried stdole.SavePicture obj.Picture, strFilePath , but that only works for button objects. 回答1: First create a Chart. Second place the picture in the Chart. Finally export the Chart. EDIT#1 For sample code see: Save Picture with VBA 回答2: I don't know if this will help, but I tried casting the

How to optimize a VBA Macro that adds a link to multiple Arabic words at once

血红的双手。 提交于 2019-12-13 07:49:37
问题 Building upon the response I receive to my previous question here, I want to create a macro to add one link to multiple Arabic words. Example: if I have a text that has: horse or horses or pony , I need to link it to horses.com . I was able to modify the original macro to add links to all of the three words successfully, but I believe that my code is bloated with repetition. My question is: is there a way to condence the code with better expressions? Here is my working code so far: Sub

Pasting two Excel ranges into an email as pictures

删除回忆录丶 提交于 2019-12-13 07:28:21
问题 I'm using a solution from Pasting an Excel range into an email as a picture. How can I paste two ranges into an email? In my attempt below, the second picture is overwriting the first picture. I would like the second picture to appear after the first one. Private Sub generateEmail(rng As Range, rng2 As Range, strName As String) 'Open a new mail item Dim outlookApp As Outlook.Application Set outlookApp = CreateObject("Outlook.Application") Dim outMail As Outlook.MailItem Set outMail =

Follow hyperlink using the VBA

≯℡__Kan透↙ 提交于 2019-12-13 07:26:05
问题 How to follow hyperlinks in Microsoft Word 2016? This works fine in Excel: ' Works in Excel Sub FollowURL() ActiveCell.Hyperlinks(1).Follow End Sub However, when I try to change ActiveCell to Selection (assuming it is necessary for Word), it doesn't work: ' Doesn't work in Word Sub FollowURL() Selection.Hyperlinks(1).Follow End Sub 回答1: What about: ' Note: Ensure the selection contains "http://..." ' for example: http://www.google.com ActiveDocument.FollowHyperlink Selection.Text Note: That