word-vba

How to use Words selection methods through Excel VBA

被刻印的时光 ゝ 提交于 2019-12-13 07:24:55
问题 In Word VBA you are able to set and move the cursor position by using the Selection.MoveLeft, Selection.MovRight etc... However while trying to use this same method in Excel VBA I get an error saying "Object doesnt support this property or method." I have imported the Word Object Library reference. How am I able to move the cursor position on the Word document using VBA on the Excel application. Any help will be greatly appreciated. Code: Set Doc = ActiveDocument.Content With Doc.Find

Update or refresh Word ContentControls

混江龙づ霸主 提交于 2019-12-13 07:22:28
问题 I have a scenario whereby I need to (programmatically) add ContextControls to a Word table. My example is when a user adds a ContentControl to a table (first cell) then adds a repeating ContentControl to that row - this is perfect! If the user then goes to cell 2 of a 2 cell table (to keep things simple) and adds another ContentControl - keeping in mind this row is already a repeating ContentControl and now just has an additional ContentControl added, the data does not repeat. If I go into my

more than one Select All Checkboxes for each frame

我与影子孤独终老i 提交于 2019-12-13 07:22:23
问题 Following Userform has 4 (Four) Select All Check-boxes . SelectAllE for Eastern Europe SelectAllA for Middle East & Africa SelectAllL for Latin America & Caribbean SA for Select All Regions (Working) only the fourth one is working correctly Following are codes for each Checkboxes Private Sub SA_Click() ' this one is working Correctly Dim ctl As Control Dim j As Long For Each ctl In Me.Controls If TypeOf ctl Is MSForms.CheckBox Then If Me.Controls(ctl.Name).Value = True Then Me.Bulgaria.Value

VBA - date minus X days from today

耗尽温柔 提交于 2019-12-13 07:15:29
问题 Here's a snippet of my invoice generator, particularly the crawler SUB that grabs the exchange rate from a webpage who's URL contains the exchange rate date. I'm trying is force it to go to a URL from Saturday if the referring date (datIzd, pulled from datIzdCtrl content control) is Sunday or Monday, because the page isn't yet generated on those days. Currently Sunday and Monday send out "out of range" error. Perhaps a much better way would be for the date to keep going 1 day back until it

Optimizing Find and Replace MS-Word VBA Script

人走茶凉 提交于 2019-12-13 04:23:05
问题 I wrote a macro for replacing the format of the first of three spaces followed by a certain string with a digit in blue font and another one for replacing the space inbetween brackets followed by a certain string. Do you know how to optimize these two procedures (I use wildcards of the search and replace dialogue of the MS-Word but guess it is rather awkard to use this in VBA..)? My macros: Sub replace_3spaces() Dim str_after As String Dim re_number As Integer str_after = "normal" re_number =

Add Header and Footer to mulitpage word doc VBA

余生长醉 提交于 2019-12-13 04:00:56
问题 I am trying to add a header and a footer to each page of a word document via a macro. I have tried a few different methods such as iterating through each shape on the page but in that case , the header and footer prints out multiple times on each page depending on how many shapes are in the document. Currently my code is looking for any current header and footer and deleting them, then it just inserts my header and footer on the first page and leaves the remaining pages in the document's

Running headers for multiple levels of headings

空扰寡人 提交于 2019-12-13 03:55:52
问题 I know, there is a simple way to create running headers using STYLEREF field. Just put this: { STYLEREF "Heading 1" } in the header of your document, and it works fine. However, the problem arises when I want to match multiple heading levels. For example, on 1st page of my document I have a Heading 1 style with text Foo . And on the 2nd page of document I have Heading 2 style with text Bar . When I'm on 1st page of document, I want to see the "Foo" in the page header. When I'm on the 2nd page

Why does this ArrayList work with no declaration in Visual Basic?

Deadly 提交于 2019-12-13 03:50:03
问题 I'm working off some example code in Word 2010, but it breaks after 10 added variables. I'm trying to understand ArrayLists in VB now. If (ActiveDocument.Name = "template.docm") Then With ActiveDocument On Error Resume Next .Variables.Add Name:="1", Value:="1" .Variables.Add Name:="2", Value:="2" I think the code starts adding objects to an ArrayList, but everything I've read on VBA Arraylists require declaration like: Dim Variables As Object Set Variables = CreateObject("System.Collections

Split Word document into multiple parts and keep the text format

江枫思渺然 提交于 2019-12-13 03:47:33
问题 My Task Split a Word document into multiple parts based on a delimiter while preserving the text format. Where I am? I tried a basic example with one document but without an array and it worked. Option Explicit Public Sub CopyWithFormat() Dim docDestination As Word.Document Dim docSource As Word.Document Set docDestination = ActiveDocument Set docSource = Documents.Add docSource.Range.FormattedText = docDestination.Range.FormattedText docSource.SaveAs "C:\Temp\" & "test.docx" docSource.Close

Use macro to search table in Word to find specific string in a cell and then set typography on another cell in the same row

我是研究僧i 提交于 2019-12-13 03:42:39
问题 I have a Word document with a table of 3 columns and an unknown number of rows and I need a macro that can search for the string "Sum" in column 1. If an exact match is found the macro must set the typography of the two remaining cells in the row to two different typographies from Word and also delete the string "Sum" in cell 1. The table can contain many instances of the string "sum" but they wil alwaye be in the first column. The code I have tried, and I apologize for my lack of coding