word-vba

creating tables in MS Word using VBA

拥有回忆 提交于 2019-12-05 18:46:06
What are the codes to create a table in MS Word? I've used the record function for macro to see how it is written and i have no idea how to interpret this. and can you not draw tables while recording a macro? It greys out the "draw table" function. I need to make a talbe that has some merged cells within the table - it would be easier if i can draw the table and record using macro but it seems like i can't do that... I've used the draw function to draw the follow table but i can't record it. HELP?! This should get you started. Sub Tester() Dim x, w, c ThisDocument.Tables(1).Delete ThisDocument

Can't get recursive Range.Find in Word VBA to work

帅比萌擦擦* 提交于 2019-12-05 16:06:17
I've been flailing at this for a while and can't seem to come up with a solution. I have to search through a document from start to finish with a wildcard search for custom mark-up. For the sake of the question, we'll say {something} When I find a specific match, it gets replaced with the contents of another string which can also contain mark-up. The mark-up has to be replaced in the order it will appear in the final document AND I have to know the recursion level that each replacement was made at. This is basically what I came up with. Note that the ProcessReplacement function is contrived

Why does VBA code run faster when called from a standard module (instead of a userform)?

喜夏-厌秋 提交于 2019-12-05 14:15:44
Alternate Title: Why does pressing Esc make my MS-Word macro run faster While waiting for some code to run I stumbled across something interesting. Code runs slow... press Esc code runs fast. Example: press Esc immediately after execution - 2 sec to complete don't press Esc at all - up to 30 sec to complete To me this makes no sense. It turns out other people have noticed similar behavior, for example: Pausing VBA and re-running it causes faster execution http://www.vbforums.com/showthread.php?490446-ESC-key-while-running-macros https://www.excelforum.com/excel-programming-vba-macros/617300

How can I loop through every letter in MS Word using VBA?

余生长醉 提交于 2019-12-05 12:32:17
I have about 100 Word documents which include transliteration of foreign names. The author of these documents used a special font called e2 which has about a dozen special transliteration characters (all of which are available in Microsoft Sans Serif font). I would like to loop through every letter of the document and whenever the .Font = "e2" I would like to loop through the dozen letters (it's easy to guess what they are) and replace them with a Microsoft Sans Serif equivalent. But I can't figure out how you can loop though letters. Is that doable like looping through cells in an Excel

Run external vba-code in MS Word

半腔热情 提交于 2019-12-05 08:33:57
Can I link in external code to a Word document? I have a lot of word documents with macros (VBA-code). All with the same code. I would like the code to be run from an external source instead of from within all of those documents. That way, if I have to update the code, I only have one place where I have to do the update. Move the code to the attached template , then the macros are available in all documents based on that template. You can create a template and put it in the %APPDATA%\Microsoft\Word\STARTUP folder, this makes the template an addin and STARTUP is a trusted location which will

Word VBA “Project is unviewable”

回眸只為那壹抹淺笑 提交于 2019-12-05 03:24:24
Does anyone know how to make a template viewable in Word 2007? I created a template, Experiments.dotm , added it using Add-Ins, but when I try to create a module within it, get an error message: "Project is unviewable" The explanation for the "Project is unviewable" problem can be found here : It is important to differentiate between opening an add-in file (for example, by clicking File and then clicking Open) and loading an add-in (for example, by using the Add-Ins button on the Developer tab). Open a file when you want to edit it and test it. Load the file as an add-in when you want to use

VBA - How to add a collection to a collection of collections

只愿长相守 提交于 2019-12-05 01:10:39
I am trying to create code to represent a form document using VBA in Word 2007. I have created classes to represent Section, QuestionSet and Question. So I have 15 Sections. I have created a function to create each 'Section' Object add it to the 'Sections' Collection then destroy the object, the result being that the objects remain persistent in the collection (or something). Is it possible to use the same method to add collections to collections or would I have to define each collection explictly? Code in Module: Public Sections As Collection Function DefineSection(ByVal SectionName As String

Inconsistent behavior for Me keyword

北城以北 提交于 2019-12-04 22:41:01
I noticed the behavior of Me keyword in VBA code in template files is different depending if the document has ActiveX controls or not. Document with ActiveX controls: Me references the new file created from template. Document without ActiveX controls: Me references the template instead of the new file. To demonstrate this strange behavior I made two sample files: WithActiveX.dotm WithoutActiveX.dotm Both files are identical, the only difference between them is that one has a Button and the other doesn't. The VBA code of both files is the following: Private Sub Document_New() Selection.TypeText

VBA Find and Replace in word based on Database in Excel

 ̄綄美尐妖づ 提交于 2019-12-04 21:06:41
I am looking for a way to Find and Replace text in a Word Document based on Data in Excel in excel More specifically: Column A = Text I want to find Column B = Text I want to replace the found text with I already know basic Find and Replace code in VBA, but I'm struggling to work out how to do it like this (Cross-application). Can anyone help me? Thanks :) REQUESTED SCREENSHOT: I've clipped a sample of my spreadsheet due to potentially sensitive information being displayed but this gives the jist. The following code needs the reference to the MS Word 14.0 Object Library or whatever is the

Get all cross references in word with VBA

前提是你 提交于 2019-12-04 17:29:01
I have quite a large word document (> 400 pages) with lots of cross references to headings. So far, I have always referred to the title of the heading, but now I would like to change that and refer to the page the heading resides on. I didn't find a solution to this via the GUI (except manual treatment, of course), so I was looking into writing some VBA. Unfortunately, I have only found a way to list all targets that can be cross referenced (via GetCrossReferenceItems ), but I need a way to access the actual cross reference field. Can you help me with that? Is a cross reference field the same