word-vba

VBA code stops whenever I open a document

空扰寡人 提交于 2019-12-21 20:38:48
问题 First of all sorry for posting this, I know it's probably duplicated from this post, I tried to post it as an edit but it got rejected and I can't comment because I don't have 50 reputation, also this is not a proper answer. Hope this helps to get a better understanding of the problem and more attention. I work in a company that uses VBA and we've been using Documents.Open for a long time and it never gave me any problems, until now. The problem seems rather random, as not many clients have

Update linked fields in Word document from Excel VBA

戏子无情 提交于 2019-12-21 17:27:31
问题 I am trying to automatically update certain information (such as names, dates and numbers) across 3 different Word documents by putting the data into a spreadsheet and linking to the respective cells from Word. The spreadsheet has some Macros in it which auto-update parts of the spreadsheet internally. Everything is working fine, except for updating the links in the Word documents. When trying to update a link in Word by right-clicking on it and selecting the "update link" option it brings up

Excel VBA: setting font style and size while adding text to MS-Word

…衆ロ難τιáo~ 提交于 2019-12-21 17:13:09
问题 I want to create a word document using Excel VBA, and add text with various font styles and sizes. Here is my code: Sub CreateNewWordDoc() Dim wrdDoc As Word.Document Dim wrdApp As Word.Application Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.Documents.Add Dim charStart As Long Dim charEnd As Long With wrdDoc For i = 1 To 3 charStart = wrdApp.Selection.Start .Content.InsertAfter (" some text") charEnd = wrdApp.Selection.End If i = 1 Then 'set the text range (charStart

VBA Inserting Comments from Excel to Word

被刻印的时光 ゝ 提交于 2019-12-20 05:39:34
问题 I'm new to VBA and I'm having difficulty trying to insert comments from data that I have in Excel onto a Word document. I am trying to write the VBA in Word and want it to extract data from a separate spreadsheet Sub ConvertCelltoWordComment() Dim Rng As Range Dim wApp As Object Dim strValue As String Dim xlapp As Object Dim xlsheet As Object Dim xlbook As Object 'Opens Excel' Set xlapp = GetObject("C:\Users\eugenechang\Desktop\...xlsx") If Err Then Set xlapp = CreateObject("Excel.Application

Blank line after deleting contentControl in word

六眼飞鱼酱① 提交于 2019-12-20 04:56:10
问题 I'm trying to write in a word document via VB.net and for this I'm using contentControls in my Word Document but sometimes I have to delete a contentControl or another via VB code. It's kind of easy with contentcontrol.delete but when this contentControl contains multipleline and I want to delete it then it leaves a blank line. How can I avoid this? 回答1: I will give you some tips based on VBA which I hope you could easily convert to vb.net and your solution. You need to cover complete range

Word deleting tabe column via vba macros gives an error

允我心安 提交于 2019-12-20 04:50:43
问题 I want to copy data from excel to the word table and then delete some columns from table. I can copy data to table, but when I delete column it gives error: Cannot access individual columns in this collection because the table has mixed cell widths. My code: Public Tbl1 As Table Sub callExcel() Dim objExcel As New Excel.Application Dim exWb As Excel.Workbook Set exWb = objExcel.Workbooks.Open("C:\Users\ismayilov\Desktop\test") roomNumber = InputBox("Enter the room number to copy word:", "Room

When using range.find to find bold text it won't find if the entire selection is bold!

老子叫甜甜 提交于 2019-12-20 03:20:32
问题 I'm trying to extract bold text using the range.find method and all is peachy except if the entire range is actually bold (not likely to happen much, it's more of an edge condition). With rngFindRange.Find .ClearFormatting .Font.Bold = True Do .Execute If Not .Found Then Exit Do End If 'do something with found text' Set rngFindRange = ActiveDocument.Range(rngFindRange.End + 1, Selection.End) Loop The above matches bold text right at the start or right at the end, even both but not when the

Recheck Document For Spellings Not Same as VBA Code

送分小仙女□ 提交于 2019-12-20 02:09:51
问题 I want to recheck the spellings in a document after adding a dictionary. The problem is the following code (mostly from the macro recorder) CustomDictionaries.Add FileName:="c:\test_dictionary.dic" Application.ResetIgnoreAll ActiveDocument.Range.SpellingChecked = False ActiveDocument.Range.GrammarChecked = False does not produce the same results as from the Word 2007's Word Options|Proofing|Recheck Document button. The button does recheck the document and you can see the newly added words get

setting system date and time using VBA

妖精的绣舞 提交于 2019-12-20 01:52:46
问题 VBA for Office2007 seems to give the possibility to set system date and time with: date = variable and time = variable however, if I try the code: Dim Datum1 Datum1 = #12. Februar 1985# Date = Datum1 I get the error message "Permission denied (Error 70)", which seems to indicate that I have no administrator rights, which is not the case. Can anybody point me in the right direction? 回答1: Use DateSerial and TimeSerial. For example: Date = DateSerial(2015, 11, 4) 'For Date changing Time =

Macro to update all fields in a word document

最后都变了- 提交于 2019-12-19 19:48:17
问题 I have built - over the years - a vba macro that is supposed to update all fields in a word document. I invoke this macro before releasing the document for review to ensure all headers and footers etc are correct. Currently - it look like this: Sub UpdateAllFields() ' ' UpdateAllFields Macro ' ' Dim doc As Document ' Pointer to Active Document Dim wnd As Window ' Pointer to Document's Window Dim lngMain As Long ' Main Pane Type Holder Dim lngSplit As Long ' Split Type Holder Dim lngActPane As