Tag: word vba

在Word中使用.Find导致无限循环

我创build了一个Loop来查找一些HTML代码的每个迭代,并以电子邮件forms返回电子邮件数据。 我们正在寻找的是: 'Jibberish HTML Code <p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p> <font color="#000000" size="2" face="Tahoma"><p><a href="mailto:last.first@location.company.com">last.first@location.company.com</a><br> 'Jibberish HTML Code <p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p> <font color="#000000" size="2" face="Tahoma"><p><a href="mailto:last.first@location.company.com">last.first@location.company.com</a><br> 'Jibberish HTML Code <p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p> <font […]

升级2013年的Word VBA代码

我有一个单词模板文件,从Excel文件中检索数据以填充表单。 代码看起来像这样: Dim myXL As Object Set myXL = Getobject("myfile.xls") myXL.Application.Visible = True myXL.Parent.Windows(1).Visible = True 此代码在Office 2010和2007中正常工作,但在2013年尝试使用时,会出现run time error 9 ,这是array subscript error 。 当我检查Windowsarrays它有零元素,所以错误是正确的。 我如何在2013年取得同样的成绩? 下一个代码试图访问Worksheets("mysheet" ),如果我跳过访问工作表的Visible = True行给出runtime error 1004. 任何帮助解决这个将不胜感激。

VBA,EXCEL,WORD:从Word中的Excel的水平行的格式

从excel VBA中,我将一个水平线添加到Word文档的标题。 Dim a As Word.Range Set a = oWord.ActiveDocument.Sections(1).headers(wdHeaderFooterPrimary).Range a.Collapse Direction:=wdCollapseEnd a.InlineShapes.AddHorizontalLineStandard 接下来我要格式化该行: a.InlineShapes(1).Height = 1 但是这个抛出和错误5941 – 收集的请求的成员不存在。 我也试过了 With a.InlineShapes.AddHorizontalLineStandard .Height = 1 End With 但也没有工作。 我尝试了Word vba中的代码,它工作。 我在这里错过了什么? 我怎样才能从Excel格式化线? 编辑 添加行后,我停止了代码。 然后我执行.InlineShapes.Count ,它返回0.然后我在文档体中添加一行并再次执行,然后返回1。 所以问题似乎是头不能从Excel访问?

使用Word VBA来自动化Excel,我得到运行时错误“13”:使用.Find函数时types不匹配

我试图从一个Excel表格获取数据到一个Word文档。 我尝试使用“查找”function,但我不断收到相同的错误“types不匹配”在这一行: Set FoundRange = .Cells.Find(260707) 这是我正在运行的子程序。 Sub GetID() Dim oXL As Object Dim oWB As Object Dim oSheet As Object Dim WorkbookToWorkOn As String Dim FoundRange As Range Dim dummyvar As String 'Start a new instance of Excel Set oXL = CreateObject("Excel.Application") 'Line to make Excel Visible or not oXL.Visible = False 'Open the […]

在Word VBA中查找字符数

我试图从Excel电子表格中dynamic生成一个Word文档。 我现在要做的方式是基本上手动查找字符数,然后最终插入给定的项目在特定的字符数。 给定的项目存储在Excel中。 所以它会是这样的: 电子表格 | 1 | 2 | 3 Char | 50 | 125 | 250 Item | Hello | Darkness | Friend 然后在VBA这个词中使用 Dim myCheck As ContentControl Dim myRange As Range Dim rng As Long rng = ''whatever char is for that column Set myRange = ActiveDocument.Range(start:=rng, End:=rng) Set myCheck = ActiveDocument.ContentControls.Add(wdContentControlCheckBox, […]

使用VBA将Excel表格中的脱节单元复制到Word表格中

我试图从excel文档中复制脱节的单元格到单词中的光标位置,并使用我预定义的表格样式。 当我复制并粘贴到当前活动工作表中时,不相交的复制/粘贴在Excel中很好地工作,但是当我尝试从单词执行相同的复制/粘贴时,它最终从左上angular复制整个表到右下方,而不是做不连贯的复制/粘贴。 我知道从excel VBA到word VBA的单独function有一些区别,但是我认为可以通过在调用函数时指定库来解决这个问题。 下面看到的是一个成功的脱节的副本: 成功的脱节复制 这里是运行的Excel代码,编辑长度。 if Copy3的代码是有趣的部分: Sub GrabExcelTables() ' !Initializing everything Dim phasesArray As Variant phasesArray = Array("Scoping", "Umsetzung (Dev)", "Go Live") With wsFrom 'Copy schema for tables 1 and 2 ' !Omitted for length 'Copy schema for tables 3 and 4 ' !Omitted for length 'Copy schema for tables 5 […]

Excel VBA:macros未识别循环中的For

以下是我正在创build的一个macros,在运行代码时遇到了一个问题。 由于某种原因,当我运行它时会出现一个编译错误,说“Next for For”,因为它在代码的末尾标识了“Next l”,但它没有标识“For l = 7 To LastRow”第一行。 有没有人有任何想法,为什么这个编译错误发生? For l = 7 To LastRow For i = 3 To LastColumn If sht.Cells(l, i).Value = "" Then V = sht.Cells(6, i).Value sTemp = sTemp & "," & V End If Next i sTemp = Mid(sTemp, 2) If Not Len(Trim(sTemp)) = 0 Then BookMarksToDelete […]

退出/重新启动控制excel的单词macros

我正在运行一个字macros 初始化Excel 在excel中创build一个临时工作簿 当退出单词用户窗体,终止excel 但是,似乎有一些剩余的Excel实例/工作簿没有完全closures,因为当我再次启动单词macros,我得到错误:462,远程服务器机器… 在word文档中初始化用户表单: private sub commandbutton1_click() dim exc as excel.application set exc as new excel.application dim wb as excel.workbook set wb = exc.workbook.saveas filename:="wordexc" 'creates temp workbook userform1.show end sub run excel processing via a userform1 commandbutton: private sub commandbutton2_click() excel.workbook("wordexc").close 'closes temp workbook dim wb as excel.workbook set wb = excel.workbook.saveas […]

从VBA Excel文件打开一个单词模板,input一个数字并打印

到目前为止,我已经在问题/解决scheme方面取得了很大的成功,并且在excel vba中获得了大量的知识,但是又一次陷入了另一种问题。 这是我的情况: 我们做一个excel vba电子表格中序列化和跟踪的样本。 可以添加多行,并通过序列号进行标识。 每个发送的样本都包含一个也被序列化的信息表。 现在,当我们将序列号input到excel中时,我们必须手动input序列号到信息表中,打印并重复。 这有时候会浪费掉,因为有时我们必须一次发送40个样本。 我的理想解决scheme 我想采取我已经到位的用户表单进行数据input,并使用列表框来logginginput到电子表格中的所有样本。 由此,如果用户决定打印纸张,他可以按命令button来运行macros。 这个macros会将列表框项目(一次一个)input到单词模板文件中的特定部分,然后打印出来。 冲洗并重复。 我真的问:任何人都可以提供一个通用的代码,从Excel中打开一个Word文件,在指定的区域input一行,然后打印它。 我现在知道一些VBA,但是这有点儿超出了我的联盟,而且有点不合时宜。 编辑:通过指定我觉得,我想有select从列表框中的文本放置在工作表上的选项。 理想情况下,这将是右上angular和中右侧。 但我需要调整位置使其完美适合! 感谢您的帮助,答:

保存生成的Word文件的唯一名称(mailmerge)

我需要我的macros的帮助。 我需要通过邮件合并保存生成的Word文件。 Sub RunMerge() Dim wd As Object Dim wdocSource As Object Dim strWorkbookName As String On Error Resume Next Set wd = GetObject(, "Word.Application") If wd Is Nothing Then Set wd = CreateObject("Word.Application") End If On Error GoTo 0 Set wdocSource = wd.Documents.Open("C:\Users\admin\Desktop\New folder (2)\G706014 ver.7.0.docx") strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name wdocSource.Mailmerge.MainDocumentType […]