Tag: word vba

使用Excel VBA代码将Word文档转换为PDF

我写了下面的代码,采取截graphics式的Excel文件,并粘贴在Word文档。它工作正常但是我无法将此Word文档转换为PDF和错误显示“对象不支持此属性或方法”。似乎我定义variables(Objword作为变体)不正确。请任何人都可以帮忙。 Sub CopyToWordPicture() Dim WDApp As Word.Application Dim WDDoc As Word.Document Dim objword As variant Set objword = CreateObject("Word.Application") objword.Visible = True objword.Documents.Open "C:\Automation\BH Report\Daily&BH RAN KPI report_ok.docx" Workbooks.Open Filename:="C:\Automation\BH Report\Daily_Hourly KPI Template.xlsx" Sheets("BH_Graphs").Select Range("A1:k50").CopyPicture xlPrinter With objword '.Documents.Add .Selection.Paste .Visible = True End With 'WDApp.Visible = True ' WDApp.Selection.GoToNext wdGoToPage Windows("Daily_Hourly KPI Template.xlsx").Activate Sheets("Daily_Graphs").Select […]

在Excel VBA中使用查找来自列表中的Word

我正在一个自动同级审查macros,将检查某些单词,并在Microsoft Word文档中突出显示它们。 不过,我正在寻找用我在Excel中创build的列表replaceWordList = Split(" is , are ,", ",") 。 这对我来说更容易添加新的单词,而不是手动input我想在代码中突出显示的单词。 例如:A1有单词“is”,所以我希望它会像Wordlist = Split("A1, A2") 或类似Exlist = Range("A1:A2").value WordList = Split(ExList) 是这样的可能吗? 感谢您的帮助。 Sub PeerReview() Dim r As Range Dim WordList() As String Dim a As Long Dim Doc As Document Dim Response As Integer 'This code will search through all of the open […]

我怎样才能使用单词的用户表单input数据以后插入到我的编码将打开的Excel文件

我有以下编码,我努力从我的用户表单input数据到我的代码将打开的Excel文件。 我已经尝试过在编码中允许代码继续,一旦我点击提交我的用户表单,但比它丢失数据或只是不input到我select的Excel文件。 因此,这不允许我从Excel中将必要的数据复制到我的Word文件中。 Sub Data() UserForm1.Show 'show the userform Dim exl As Object 'exl ist der Verweis auf Excel Dim oExl As Object Dim ImportDatei As Variant Set exl = CreateObject("excel.application") ImportDatei = exl.Application.GetOpenFilename(FileFilter:="Microsoft Excel-Dateien (*.xlsm), *.xlsm", Title:="Eine Datei auswählen") 'ab exl. wir der Excel Befehl angefügt If ImportDatei = False Then Exit Sub exl.Workbooks.Open […]

Excel中的Word报告自动化来源编号

我需要通过从Excel中提取数字来自动进行报告。 我search并遵循源自http://www.makeuseof.com/tag/integrate-excel-data-word-document/的代码 代码无法正常运行,并遇到一些错误。 1. Excel未打开2.遇到运行时错误“438”:对象不支持此属性或方法。 我使用了网站build议的“早期绑定”代码,并且不工作,研究使用“后期绑定”。 仍然不起作用。 我插入“Microsoft Excel 14.0对象库”并在Word文档的“ActiveX控件”下插入“标签” 不知道出了什么问题。 当前的vba代码 Private Sub CommandButton1_Click() Dim objExcel As Object Set objExcel = CreateObject("Excel.Application") Set exWb = objExcel.Workbooks.Open("C:\Users\adong\Desktop\Reporting.xlsx") ThisDocument.DMY.Caption = exWb.Sheets("Summary").Cell(5, 4) exWb.Close Set exWb = Nothing End Sub 先前的代码 Private Sub CommandButton1_Click() Dim objExcel As New Excel.Application Dim exWb As Excel.Workbook Set exWb = objExcel.Workbooks.Open("C:\Users\adong\Desktop\Reporting.xlsx") […]

引用excel VBA中的单词表?

我正在尝试编写一个excelmacros来打开一个rtf文档,并根据几个variables(pulldate和rmname)返回特定表的页码。 下面的代码在Word VBA中完美地工作(当然,使用“activedocument”来代替“wdApp”),但是当我尝试从excel中实现时,它会中断。 Sub find_pulls() Dim wdApp As Object Dim pullsheets As Object Dim totalPullPages As Integer Dim pg As Pages Dim start As String Dim finish As String Dim rmname As String Dim tnumber As Integer Dim pSnumber As String Dim pEnumber As String Dim pulldate As String Set wdApp = CreateObject("word.application") Set pullsheets […]

检查是否从Excel VBAclosuresWord文档

我正在执行几个打印的embedded式Word文档巫婆有一些字段链接到一些单元格,通过我的PrintOutmacros,在For..Next循环,如下所示。 我需要在每个打印任务后,该程序等待文档closures,然后进行下一个打印。 在这种情况下,我收到错误。 谁能帮忙? Sub contract() Dim i As Integer For i = 1 To 100 Cells(Sheets("SheetName").ListObjects("StaffInfo").ListRows.Count + 9, 8).Value = i General.PrintIt ("EmbeddedDoc") 'Doc has many linked fields Next i End Sub 打印方法 Sub PrintIt(P As String) Dim objWord As Object Dim ObjDoc As Object Dim Oshp As Object Application.ScreenUpdating = False ActiveSheet.OLEObjects(P).Activate Set […]

将文本从Excel中的范围复制到Word文档中

你怎么: 1)从Excel文档中的范围复制文本。 2)打开一个Word文档。 3)将文本插入到word文档的特定部分。 问候 科乔 编辑:这是方法 Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim j As Integer Set wrdApp = CreateObject("Word.Application") wrdApp.Visible = True Set wrdDoc = wrdApp.Documents.Open("C:\Files\DailyStrategy.doc") With wrdDoc If wrdDoc.Bookmarks.Exists("MarketCommentry") Then wrdDoc.Bookmarks("MarketCommentry").Range.Text = shortString wrdDoc.SaveAs "c:\temp\test.doc" End If ' close the document Set wrdDoc = Nothing Set wrdApp = Nothing End […]

Word vba document.readonly状态错误地返回false

我有一个Excel项目,检查单词文件的更改修改date,如果更改,它将打开该文档,并从Word表单字段中的文本导入到Excel中。 在excel中打开和导入word文档的例程如下: Sub CopyFromWord(pFile as String,aFile as string) Dim wdApp As Object On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Set wdApp = CreateObject("Word.Application") Else 'word is already running End If On Error Goto 0 Set wdDoc = wdApp.Documents.Open(Filename:="" & pFile & "", ReadOnly:=True) wdApp.Visible = False For Each […]

使用Excel 2010 vba创build一个由多个word文件组成的文本文档

这是我想要做的: 我有一个Excel工作表,用户可以select一些关键字。 对于每个关键字,都有一个具有相同名称的单个Word文档,其中包含有关关键字的一些文本。 做出select后,我希望用户点击一个命令button,然后创build一个新的Word文档。 这个新的Word文档将包含从对应的Word文档中select的关键字和文本。 样式和形成生成的Word文档并不重要。 将不同文本与不同文档分开的空白行就足够了。 我想用Late Binding来做到这一点,因为在VBA中添加引用时遇到问题(访问系统registry时出错) 我应该如何开始,在哪里寻找例子? 我有中级Excel VBA经验,但完全不熟悉跨应用程序和Word属性。

删除Word字段VBA不能在Word 2013中工作,在Word 2010中工作

我有一个从Excel运行的VBAmacros从Word文档导入一些信息。 在我开始parsing之前,我想摆脱目录和其他领域。 下面的代码(剥离到最低限度)在Office 2010中工作,但不在Office 2013中。我得到一个“方法删除对象字段失败”的错误信息,但我不明白为什么。 感谢您的任何提示! 博 Sub ImportBOD() Dim wdFileName As Variant Dim WordApp As Object Dim wdDoc As Word.Document Dim fld As Word.Field wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", ,"Choose the Word document") If wdFileName = False Then Exit Sub '(user cancelled import file browser) Set WordApp = CreateObject("Word.Application") Set wdDoc = WordApp.Documents.Open(wdFileName, ReadOnly:=True) […]