word-vba

Deleting columns from a table with merged cells

对着背影说爱祢 提交于 2019-12-06 19:29:50
问题 I'm trying to delete columns from a table which has horizontally merged cells Selection.MoveEnd Unit:=WdUnits.wdCell, Count:=3 Selection.Columns.Delete Eventhough columns are getting deleted, merged cells are removed in the process leaving a broken table. Almost similar approach to delete rows works fine as explained in this answer Workaround I'm doing something like this as work around Selection.MoveEnd Unit:=WdUnits.wdCell, Count:=3 Selection.MoveDown Unit:=WdUnits.wdLine, Count:=2, Extend:

Inconsistent behavior for Me keyword

我怕爱的太早我们不能终老 提交于 2019-12-06 17:07:23
问题 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

“Find and Replace” multiple words in Word from Excel list

家住魔仙堡 提交于 2019-12-06 16:53:54
问题 I have created a find and replace Macro in MS Word that replaces word A with B. Ok, but now I have 50 words that need replacing. That means I will have to create a new entry for each word, which will take FOREVER. Plus a few weeks from now I will have to add more words to be replaced. Is there a way to link a word list via excel, say words in column 1 are the words I want replaced with the matching words in column 2? Here's what I have so far. Sub Macro5() ' ' Macro5 Macro ' ' Selection.Find

Save the active open document as pdf file

你说的曾经没有我的故事 提交于 2019-12-06 16:44:15
I have the below code that copy range cell values from excel and paste as picture in a new word document. I want to save the active document as pdf file with name of file as value in cell "A2". If you can help me in adding the same in the below code it would be a great help. Sub Picture() Dim objWord, objDoc As Object ActiveWindow.View = xlNormalView Range("A2:K25").Select Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Add objWord.Visible = True objWord.Selection.Paste objWord.Selection.TypeParagraph

MS Word SaveAs, check “Maintain Compatibility” via VBA

扶醉桌前 提交于 2019-12-06 16:43:25
There's a check box "Maintain compatibility with previous versions of Word" in "SaveAs" dialogue box, by recording a macro and have the check box ticked, I got ActiveDocument.SaveAs2 FileName:= _ "C:\Users\jondoe\123.dotm", _ FileFormat:=wdFormatXMLTemplateMacroEnabled, LockComments:=False, _ Password:="", AddToRecentFiles:=True, WritePassword:="", _ ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False, CompatibilityMode:=12 tick it off, the only difference is CompatibilityMode:=15 according to

Creating Word or XML document with VBA

旧时模样 提交于 2019-12-06 15:31:56
I need to create documents, (~150 reports, letters) mostly from pre-existing snippets and local databases, with VBA, in Word 2003. I then need to change specific parts of those snippets, such as dates, phrases, user information, &c. There are also, obviously, some bits that I will generate in my program. Currently, this same task is done (sort of) by some hideous legacy VBA. (Nested IFs and FORs, and over 200 textboxes all called TextBox#) It gets the job done SOMETIMES, and does so by sending instructions to the Word application ( Selection.MoveDown Unit:wdLine, Count:=1 , for example.)

How to delete a section using excel-vba to create a word document

吃可爱长大的小学妹 提交于 2019-12-06 15:30:18
Hello and thank you in advance. I am creating a very complex Word document out of an Excelfile using VBA. It shall be possible to activate something and a text written in a cell shall be transfered to the word document. I got that already done. But if it is not activated the tag "<>" shall be removed, leaving nothing behind. This means that it shall remove not only the text, it shall remove the complete "line". As line might be a section i am not sure if just line is the correct word here. Right now I find and replace them with "" using: With WordDoc.Content.Find .Execute FindText:

Running python from VBA word and returning a value

微笑、不失礼 提交于 2019-12-06 15:15:17
Trying to figure out how to open python from word vba, on mac computers, and return a value using the code below. I need to be able to run this code from word vba without calling a specific python file, this will be run on multiple computers so I can't assume they have my premade python file downloaded. All I've seen is people calling a premade file with the script already in it. Here is my Python Code: import urllib2 web1 = urllib2.urlopen('website.com') #website url print(web1.read()) Any suggestions or links to a place that could help? Edit: Current Working Code myAppleScript = "do shell

VBA Find and Replace in word based on Database in Excel

倾然丶 夕夏残阳落幕 提交于 2019-12-06 14:50:16
问题 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

Range.InsertXML using Transform

强颜欢笑 提交于 2019-12-06 13:42:56
I am using Range.InsertXML to add formatted content to an existing MS Word document. AFAICT, the method .InsertXML takes parameters XML as a string and XLST (Transform) as a variant; however the documentation for .InsertXML is lacking in that it does not provide an example that includes the use of Transform. In responding to this question: Range.InsertXML throws when inserting Open XML Cindy Meister linked to an excellent resource that explains lotd about Words XML and how to use it, but I still can't find any examples where Transform is used. What I am trying to do is the same as in this