Tag: word vba

从Word中提取embedded的Excel工作表数据

我有一批embeddedExcel工作表的Word文档。 用户通过双击工作表图像并打开embedded的Excel对象,可以在Excel工作表中input数据。 我需要去用户input的数据。 下面是WORD VBA引用Microsoft Excel 15库。 (在Office 2010下创build的Word和Excel对象) 我可以findOLE对象,但我无法做任何事情。 在下面的代码中,我尝试将对象分配给一个Worksheet对象,但是我得到一个types不匹配的错误。 为了使事情进一步复杂化,embedded的Excel工作表具有macros。 在问题的某些过程中,将打开一个Excel窗口,提示是否启用macros安全提示。 我很可能暂时禁用macros检查,以通过这个。 我所需要做的就是获取工作表中的数据,将其复制到别处一次。 如果可能的话,我会很高兴将工作表复制到外部文件。 我有Office 2010和2013,以及Visual Studio 2010 Pro和2014 Express。 我怎样才能到达embedded式工作表数据? Sub x() Dim oWS As Excel.Worksheet Dim oIShape As InlineShape For Each oIShape In ActiveDocument.InlineShapes If Not oIShape.OLEFormat Is Nothing Then If InStr(1, oIShape.OLEFormat.ProgID, "Excel") Then oIShape.OLEFormat.ActivateAs (oIShape.OLEFormat.ClassType) 'Excel.Sheet.8 Set oWS = […]

从excel导出数据到word,while函数

我试图从excel导出数据到word,但在while语句的乞讨中出现了一些问题。 出于某种原因,我得到一个错误在行ReDim Preserve zPList(zIndex) As personClass ,错误是下Subscript out of range 。 有人可以帮忙吗? Public Sub GetExcelData(ByRef zPList() As personClass, ByRef zIndex As Integer) Dim tempStr As String tempStr = "" Dim row As Integer row = 2 While tempStr <> "zzz" zindez = zIndex + 1 ReDim Preserve zPList(zIndex) As personClass Set zPList(zIndex) = New personClass […]

从Excel中replaceWord书签中的图像

我有一个打开的Word文档,有一堆书签,每个书签都有一个以前从Excel导出的Excel表格的内嵌图像。 现在,我需要更新Word文档中的表格,因为它们在Excel中已更改。 我这样做的方式是将Excel中的表名与Word中的书签名称进行匹配。 如果它们相等,我想用现有的replaceWord中现有的图像。 这是我的代码到目前为止: Sub substituir() Set WordApp = GetObject(class:="Word.Application") Set DocumentoDestino = WordApp.ActiveDocument For Each folha In ThisWorkbook.Worksheets If folha.Visible Then 'loop all excel tables For Each tabela In folha.ListObjects tabela.Name = Replace(tabela.Name, " ", "") nomeTabela = tabela.Name For Each myBookmark In DocumentoDestino.Bookmarks If Right(myBookmark.Name, 4) = "PGST" Then 'This is where […]

将variables从XLSM传递到embedded的DOCM

我有一个embedded的Word文档(*.docm)在我的Excel工作表中。 Word文档包含一个table ,它与Excel的WorkSheet Table中的相应Table之间有关系。 我想要在Document_Open事件中dynamic地设置embedded式Word文档中表格行的数量,以及其涉及的工作表中的波纹pipe值: ThisWorkbook.Worksheets("Sheet1").ListObjects("Salary").ListRows.Count 如何在Excel(macros容器文档)和其embedded的macros容器文档之间传递值? – 如果它是上述大胆的问题的正确答案或另一个解决scheme? 如果有另一个解决scheme的答案,请注意封面需要: 使用源数据中的相应值填充目标表(即在embedded式文档文档中)的单元格位于Worksheet?的父表中,而不是自动生成具有来自macros容器embedded的Word文档的Document_Open事件的字段。

MS Word中的链接表

我想使用VBA以编程方式刷新Word模板报表中的Excel表格。 这些表格是从Matlab的模板Excel文件中写入到几张表格中的。 文件结构如下所示: 代码将不得不检查文件夹结构以查看是否将Excel文件从最新的文件夹中提取出来。 如果是这样,它只会刷新所有的细胞。 如果不是,则必须删除所有的表格,并从前面的表格中插入新的表格。 我不确定下面星号之间的代码。 任何帮助将非常感激。 Sub LinkToCurrentTableFolder() 'Get current folder by date Dim clientTablesPath As Variant filePath = ActiveDocument.Path & "\ClientTables\" Set fso = CreateObject("Scripting.FileSystemObject") Set fld = fso.GetFolder(filePath) Dim currentFolder As Variant: currentFolder = "" For Each sf In fld.SUBFOLDERS 'Look at name and get current date If currentFolder = "" […]

使用一个variables来select一个ActiveX控件checkbox的名称(在Excel中的Word)?

这行代码有什么问题? WordDoc.CheckBoxNum.Value = CheckBoxVal 要清楚,我正在使用ActiveX控件“checkbox”。 我有值(真/假)和checkbox名称保存在Excel文件中。 代码打开我的Word文档,并自动循环checkbox,设置它们的值。 我从Excel控制单词的事实可能会改变我的对象? 如果他们是forms领域…这个作品 – CheckBoxNum = "Check1" CheckBoxVal = "True" WordDoc.FormFields(CheckBoxNum).CheckBox.Value = CheckBoxVal 这是我的整个代码 Sub Doit() Dim WordApp As Object Dim WordDoc As Object Dim filepath As String Dim CheckBoxNum As String Dim CheckBoxVal As String Dim i As Integer, k As Integer 'Open Word filepath = "C:\test.docx" Set […]

在Excel中的单词replacemacros不起作用

我正在尝试将我的Excel结果input到预先创build的Word文档中。 我想用这个macros。 我对代码写作游戏相当陌生,但是我理解基础知识。 我试图从不同的课程复制,但没有任何作品。 这个简单的macros应该改变'x1'为'任何',但它所做的只是打开文档并select文档中的x1。 有谁知道我哪里错了? Private Sub CommandButton1_Click() Set wrdApp = CreateObject("Word.Application") wrdApp.Visible = True Set wrdDoc = wrdApp.Documents.Open("C:\Users\mycomputer\Documents\PremadeDocument.docx") wrdApp.Selection.Find.ClearFormatting wrdApp.Selection.Find.Replacement.ClearFormatting With wrdApp.Selection.Find .Text = "x1" .Replacement.Text = "anything" ' .Forward = True .Wrap = wdFindContinue ' .Format = False ' .MatchCase = False ' .MatchWholeWord = False ' .MatchWildcards = False ' .MatchSoundsLike […]

当单词未打开时,从Excel中的模板创build单词文档

我有一个生成一些graphics的Excel文件,我试图在Word中创build一个报告,这些graphics拉一些。 我有一切设置和工作,但Word文件不生成,除非Word已经打开。 这是我到目前为止的片段 – 我错过了什么? Sub Generate_Report() Dim wordApp As Object Dim templateFile As Object On Error Resume Next ' Define template word file Set wordApp = GetObject(, "Word.Application") 'gives error 429 if Word is not open If Err = 429 Then Set wordApp = CreateObject("Word.Application") 'creates a Word application ' wordapp.Documents.Open ThisWorkbook.Path & "\WeatherShift_Report_Template.docm" […]

从excel中添加页码到VBA

我有以下代码,有足够的帮助我获得: 'sidnummer Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="PAGE ", PreserveFormatting:=True 唯一的问题是,它出现了一个错误,说: “错误的参数数量或无效的属性分配” 我该如何解决这个问题?

检查dynamic添加的combobox中的用户input数据

我正在使用用户窗体来显示在文档中find的首字母缩略词和首字母缩写词的定义。 因为我不会提前知道有多less我会创build所有的标签,dynamiccheckbox和comboBox使用下面的for循环。 我现在卡在我想让用户能够键入combobox一个新的定义是例如一个不存在于我的Excel数据库或他们想要使用一个不同的定义,我知道这是不好的做法,但不幸的是,人们不坚持标准清单)。 现在所有的工作正常,但它的设置,但我的问题是,我想检查用户是否input了新的东西或不。 所以我的问题是,是否有一个内置函数或variables这样做? 还是有一个简单的方法来做到这一点? (我已经试过并testing了将string添加到我的数据库的代码,所以这不是一个问题,只是检查它是否不存在,而无需再次从头开始运行整个数据库) For i = 1 To n checkBoxi = "CheckBox" & i labeli = "Label" & i comboBoxi = "ComboBox" & i 'add checkbox, label and combobox .MultiPage1.Pages("Page1").Controls.Add "Forms.CheckBox.1", checkBoxi .MultiPage1.Pages("Page1").Controls.Add "Forms.Label.1", labeli .MultiPage1.Pages("Page1").Controls.Add "Forms.ComboBox.1", comboBoxi 'position check box .MultiPage1.Pages("Page1").Controls(checkBoxi).Left = LeftSpacing .MultiPage1.Pages("Page1").Controls(checkBoxi).Top = TopSpacing + rowHeight * i […]