word-vba

Word 2013 VBA - opening document aborts macro

可紊 提交于 2019-12-12 03:27:15
问题 I'm running pretty simple VBA in Word: Sub Something On Error GoTo prob Dim d As Document Set d = Documents.Open(FileName:="c:\ajb files\test.docx") 'this should run if macro succeeds MsgBox "ok" Exit Sub 'this should run if macro fails prob: MsgBox "prob" End Sub This macro opens the Word document then stops (without triggering an error message). I tried running the same macro in Word 2010 and it works fine. I haven't got an Acer laptop, or any weird anti-virus or other software running. I

Word VBA to delete Content Controls with specific Tags

ε祈祈猫儿з 提交于 2019-12-12 03:08:05
问题 I read the answers to the question on How to find and disable a content control by tag on SO (below is the code for your convenience). In my case, I need to delete Content Controls (CC) with SPECIFIC tags. For Example, out of the 150 CCs that I have in the document, I need to find and delete only those CCs with the Tag "DCC" (just the CC, not its contents). As you can tell, I have no/limited experience in VB and would greatly appreciate a script that I can copy/paste. I'm using Rich Text CCs

Get Word bookmark index to replace image inside bookmark from Excel

徘徊边缘 提交于 2019-12-12 01:49:26
问题 This question is related with a previous one. I have an open Word document with a bunch of bookmarks, each with an inline image of an Excel table previously exported from Excel. Now, I need to update the tables in the Word document as they have changed in Excel. The way I'm doing this is matching the table names in Excel with the bookmark names in Word. If they are equal than I want to replace the existing images in Word by the current ones. This is my code so far: Option Explicit Sub

How can I move the cursor to a postion where I want in office word by vb?

我怕爱的太早我们不能终老 提交于 2019-12-12 01:12:56
问题 12345qwesdfasdf22232 & 021930 Like the string above, I want to move the cursor to the position after the character & by searching the character in the string. How can I achieve it when I using visual basic to control the word? Option Explicit Dim WordApp As Word.Application Private Sub Command2_Click() Set WordApp = New Word.Application WordApp.Documents.Open CommonDialog1.FileName WordApp.Visible = True WordApp.DisplayAlerts = False ... End Sub 回答1: If you are outputting using Selection

Word 2010: How do I attach a ribbon button to a template using VBA

淺唱寂寞╮ 提交于 2019-12-11 21:27:48
问题 I want to assign a macro to a custom ribbon button on Word 2010 BUT ONLY FOR A PARTICULAR TEMPLATE FILE so that the button only appears when that template has been attached to the file I'm working on. There will be about 30 users using this over the network in my office, so the idea is that storing the button on the template file will allow the button to be portable to other users without me having to manually install it on each user's PC. 回答1: Create a macro-enabled template file (with the

VBA(?) How to extract filename of images linked and inserted - Word 2013

喜夏-厌秋 提交于 2019-12-11 21:12:45
问题 We insert and link pictures (insert picture from file .emf) in our Word documents (.docx). Our documents and the graphic files are stored on our network drives. We then provide our documents to the authors to be worked on. The pictures in the documents are useful for the authors. How do I programmatically and globally (document wise, not batch processing documents): Extract the filename (without the file extension) of the pictures linked and inserted? We have a tool that exports the Word

Distribute Column Width on Table of Word Document

笑着哭i 提交于 2019-12-11 20:39:14
问题 My goal is to go to the top of the Word document, find the 6th table, and format the table to "Arial" and font 9 and distribute the column width. The problem is that it doesn't distribute the column width but does the other two. Sub TableFormat() Selection.GoTo wdGoToPage, wdGoToAbsolute, 1 Selection.GoTo What:=wdGoToTable, Which:=GoToNext Selection.GoTo What:=wdGoToTable, Which:=GoToNext Selection.GoTo What:=wdGoToTable, Which:=GoToNext Selection.GoTo What:=wdGoToTable, Which:=GoToNext

Document.Save is Showing SaveAs Dialog

佐手、 提交于 2019-12-11 20:35:13
问题 I have a Visual Studio 2010 VB.NET 4.0 Windows Application project. The code is populating a Word 2010 document. There are anywhere in the region of 30 to 60 tables and anywhere in the region of 30 to 50 embedded charts (all defined as inline shapes ( InlineShape )). I had to start putting in regular Document.Save() calls as I was getting the following error: There are too many edits in the document. This operation will be incomplete. Save your work. . There is plenty of disk space available

Printing a String in italics

巧了我就是萌 提交于 2019-12-11 17:50:00
问题 I am taking input as strings from a Userform and I need to output them in a cell. In the output, all the strings are concatenated but only a few them italicized. I am unable to output the strings italicized. I have tried searching the documentation, stack exchange and few other blogs but all of them require selection from a cell rather than manipulating the string obtained from Userform . Any help or pointers are greatly appreciated. Output now: [1] R. Welder. How to weld. Welding Shop:

Export from Excel to a word Document and insert a header in word

丶灬走出姿态 提交于 2019-12-11 17:39:18
问题 I have the following code: Sub CreateRapport() Dim wdApp As Object Dim wd As Object On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Set wdApp = CreateObject("Word.Application") End If On Error GoTo 0 Set wd = wdApp.Documents.Add wdApp.Visible = True Sheets("Rapport").Activate Set Rng = ThisWorkbook.ActiveSheet.Range("A1:E76") Rng.Copy With wd.Range .Collapse Direction:=0 'Slutet av dokumentet .InsertParagraphAfter 'Lägg till rad .Collapse Direction:=0