word-vba

import folder of .txt files into word document

我与影子孤独终老i 提交于 2020-02-23 04:09:52
问题 I've found a lot on importing folder of .txt files into excel, but not many on importing .txt files into word. I'm trying to get my macro to open all .txt files in a specific folder and import them into a single word document, with each .txt file having its own page. This is the code I have so far (that I found online): Sub AllFilesInFolder() Dim myFolder As String, myFile As String myFolder = Application.FileDialog(msoFileDialogFolderPicker) With Application.FileDialog

VBA to copy text from excel to on specific location in wordfile

限于喜欢 提交于 2020-01-30 11:01:09
问题 Problem: Pasting copied data from excel to specific location in a word file. Currently I have code which can paste the value, but it does so to "paragraph1" myDoc.Paragraphs(1).Range.Paste How do I specify the exact location (by line) in which to paste the data? Let me know if more info is required. Thanks! Mohd Akhtar 回答1: You could also use some bookmarks: You can choose where you put your bookmark and then write on it like this ThisDocument.Bookmarks("NAME_OF_THE_BOOKMARK").Range.Text =

highlight current line of word document when move up or down

不想你离开。 提交于 2020-01-25 06:16:39
问题 I wanted to develop a program such a way that when up or down arrow moved, highlight the entire line of text. So when I go up or down with arrow keys it highlight the line where my cursor is. So I developed this code. Application.ScreenUpdating = False Dim currentPosition As Range Set currentPosition = Selection.Range 'pick up current cursor position Selection.WholeStory Selection.Range.HighlightColorIndex = wdNoHighlight currentPosition.Select 'return cursor to original position Selection

How do you correctly set document properties using VBA?

瘦欲@ 提交于 2020-01-24 02:16:21
问题 The problem I'm having some trouble setting document properties using VBA in Word 2010. I have a document containing several Heading 1 sections and I use a macro to extract a selected section (along with it's contents) and paste it to a new document. This part works fine, but at the end I need to set several document properties, but none of them are being set. I'm trying to set both built-in and custom properties, but for the purpose of this question I'd like to set title , subject and,

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

流过昼夜 提交于 2020-01-23 13:07:07
问题 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.

Copy shape in Word 2010 without .Select?

给你一囗甜甜゛ 提交于 2020-01-23 10:55:12
问题 Is it possible to copy a shape in Word 2010 without resorting to .Select ? According to Dev Center the Anchor property returns the shape's anchoring range. Could that be a way forward? However, the code below returns an error. Sub createShape() Set myShape = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1) myShape.Anchor.Copy End Sub 回答1: While it does not seem to be possible to copy a shape without selecting it, it is possible to duplicate a shape without selecting it (which was

How to insert shape in cursor position when user clicks

五迷三道 提交于 2020-01-22 03:57:05
问题 I am trying to insert a shape in a position of cursor where user click by an event WindowBeforeDoubleClick, but when I use the code below its relate to screen coordinate so it is not placing in word page properly. can anyone suggest how to find the page margin coordinate or any other in order to place the shape at cursor point in word. This is the code Public Sub addWin() ActiveDocument.Shapes.AddShape(msoShapeRectangle, MouseX, MouseY, 20#, _ 16#).Select Selection.ShapeRange.Name = "WK# " &

Script for changing fonts in a Word document

眉间皱痕 提交于 2020-01-21 19:39:40
问题 I have a Word 2007 file and I want to change all usage of the Courier New font into a Lucida Console font. I need a script that find all words formatted in that font and change it to the new font. How can I do that? 回答1: Inside Word, you can record a macro by doing it yourself. Then you open the VBA editor, optionally remove some useless thing (usually too many selections or moves within the file) and you've got your script. Edited: moved the contents of a comment here, to answer the author's

How to Edit a Read-Only Word Document (VBA)

匆匆过客 提交于 2020-01-17 08:37:47
问题 I am periodically getting Word documents from various clients and sometimes they send them to me in 'Read-Only' mode. While it isn't a big deal to go to 'View > Edit Document' manually, I cannot seem to find how to do this within my VBA code. Either opening a document as editable or toggling it as editable once it is open would be sufficient for my needs. Note that I cannot open the document with 'readOnly = false' as it looks like it is set to 'readOnly recommended' (based on my reading of

How to Edit a Read-Only Word Document (VBA)

谁说胖子不能爱 提交于 2020-01-17 08:37:08
问题 I am periodically getting Word documents from various clients and sometimes they send them to me in 'Read-Only' mode. While it isn't a big deal to go to 'View > Edit Document' manually, I cannot seem to find how to do this within my VBA code. Either opening a document as editable or toggling it as editable once it is open would be sufficient for my needs. Note that I cannot open the document with 'readOnly = false' as it looks like it is set to 'readOnly recommended' (based on my reading of