word-vba

How to get data from an already opened excel workbook with a Word macro?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 21:09:20
问题 I am currently struggling with a vba macro, could you help me please? I would be very thankful to anyone who can help me on this. I want to access data of an Excel opened workbook from a Word Document macro. For some reasons I need to take data from the Excel workbook which is already opened on my user session and not to reopen it in the background by using its path. Here is the current bit of macro I want to transform so that I use the “GUI.xls” which is already opened. The window’s name is

What is a story?

情到浓时终转凉″ 提交于 2019-11-30 20:22:17
In MS Word VBA, what is the unit of measure "Story" and where does it fit into the hierarchy of units in a Word document? This reference only says that wdUnits.wdStory refers to "a story" which is not helpful. I couldn't find any other references that explain what I'm looking for. This is actually a more complicated question than most would think. In a Microsoft Word blog post stories are defined as: "...distinct regions of content that make up a Word document and share properties and functionality. Put differently, behind the scenes, Word breaks all documents up into a collection of chunks

What is behind this difference in parentheses effect in VBA?

点点圈 提交于 2019-11-30 20:13:22
问题 I've not seen this in other languages but I see it a lot in VBA (which I just started working with). Suppose you have a table in Word and wish to set the rows to a certain height. If you do this tbl.Rows.SetHeight InchesToPoints(1), wdRowHeightExactly the table's rows indeed are set to 72 points or 1 inch in height. However, if you surround the arguments in parentheses, something I did instinctively, VBA gives an error -- expected:= . I can solve this by using a throw-away variable, like this

Automated Word Template Creation With VBA

馋奶兔 提交于 2019-11-30 20:11:32
I am creating a word document template and am at a bit of a crossroads. I would like to populate the document with figures created from MATLAB and Excel tables populated from MATLAB outputs. The figures are organized into folders and the Excel tables are organized in sheets in an Excel template as shown here: I have asked several previous questions here with respect to automatically updating these tables and figures and now have the code for this: Linked Table in MS Word Linked Images and Tables in MS Word The reports are long but vary in length. The reports document machine tests. Some

Excel/Word Equations using oMath.BuildUp method?

流过昼夜 提交于 2019-11-30 16:14:36
问题 I am trying to automate process of generating Equations in Microsoft Word 2010 using VBA and inserting those into Excel since it doesnt support oMath object. Problem lies in oMath.BuildUp method. It doesnt interpret stuff like \sqrt, \times, \delta in the same way that it is interpreted when entered by hand. For example entering code Celsius = \sqrt(x+y) + sin(5/9 \times (Fahrenheit – 23 (\delta)^2)) into Equation will give this result http://i43.tinypic.com/10xc7zp.jpg which is fine. But

Building Word fields

独自空忆成欢 提交于 2019-11-30 15:58:56
Apart from just inserting and parsing text into a blank Word field, is there any way to programmatically build user-defined fields and field codes into my own templates with VBA? Furthermore, is there a way to make these fields show up in the list of available fields? I recently developed a solution that used Word's MACROBUTTON and ADDIN field types. I found MACROBUTTON useful because the third whitespace-delimited entry inside the field (programmatically field.code.text) is displayed within Word. This allows my users to watch fields as they move around. { MACROBUTTON NoMacro * } would display

Excel/Word Equations using oMath.BuildUp method?

前提是你 提交于 2019-11-30 15:50:52
I am trying to automate process of generating Equations in Microsoft Word 2010 using VBA and inserting those into Excel since it doesnt support oMath object. Problem lies in oMath.BuildUp method. It doesnt interpret stuff like \sqrt, \times, \delta in the same way that it is interpreted when entered by hand. For example entering code Celsius = \sqrt(x+y) + sin(5/9 \times (Fahrenheit – 23 (\delta)^2)) into Equation will give this result http://i43.tinypic.com/10xc7zp.jpg which is fine. But when using macro VBA or recording macro this Method is not working as it should be and it gives result

Regex Microsoft Word without destroying document formatting

扶醉桌前 提交于 2019-11-30 15:22:14
It's well known that word's find and replace "wildcards" features suffer some severe limitations. The following code implements true regex find and replace in a word document, and variations on it are found in other Stackoverflow and SuperUser questions. Sub RegEx_PlainText(Before As String, After As String) Dim regexp As Object Set regexp = CreateObject("vbscript.regexp") With regexp .Pattern = Before .IgnoreCase = True .Global = True 'could be any Range , .Range.Text , or selection object ActiveDocument.Range = .Replace(ActiveDocument.Range, After) End With End Sub However, this wipes the

Create Range from current cursor position Word 2010 VBA

笑着哭i 提交于 2019-11-30 14:24:54
问题 I have a .docm document with a user form. On the user form I have a button that needs to insert something (some text, for starter) at the last known cursor position in the document. For this, I want to create a range. How can I get the starting position for this range? 回答1: Selection is the current position in the document. Selection.Range is the Range object of the current Selection . Range.Start is the start position of a Range object (returns or sets a Long). If you combine those three you

Highlight (not delete) repeat sentences or phrases in a word document

隐身守侯 提交于 2019-11-30 12:57:25
问题 I am getting the impression that this is not possible in word but I figure if you are looking for any 3-4 words that come in the same sequence anywhere in a very long paper I could find duplicates of the same phrases. I copy and pasted a lot of documentation from past papers and was hoping to find a simple way to find any repeated information in this 40+ page document there is a lot of different formatting but I would be willing to temporarily get rid of formatting in order to find repeated