vba 相关问题

Visual Basic for Applications(VBA)是一种用于编写宏的事件驱动的面向对象编程语言,用于整个Office套件以及其他应用程序。 VBA不等同于VB.NET或VBS;如果您在Visual Studio中工作,请使用[vb.net]。如果您的问题专门针对编程任何MS Office应用程序,请使用相应的标记:[excel],[ms-access],[ms-word],[outlook]或[microsoft-project]。

将2-D阵列转换为1-D阵列和粘贴1-D阵列到另一张纸

带有公式的区域表1.range(“ A2”)的细胞范围。 “无数据”字符串是恒定的,如果没有按照公式提取任何内容,我不希望它将其包含在1-D数组中...

回答 2 投票 0



我不想从Excel细胞中提取图表数据

以下代码效果完美。 公共sub macro1() '将今天的日期输入A1和A2单元。 ActivesHeet.range(“ A1”)。值= NOW() ActivesHeet.range(“ A2”)。值= NOW() '...

回答 1 投票 0



回答 1 投票 0

用户形式在Word Document中的书签中输入值

我希望用户形式在Word文档中的预定书签中输入某些值。 私有sub commandbutton2_click() 昏暗的下krivtitel作为范围 设置underskrivtitel = activedocument.bookmarks(

回答 1 投票 0

我在myexcel.xlsx中具有电源查询。我将其连接的属性设置为 this

Sub UpdateData() Dim filename As String Dim wbResults As Workbook filename = "C:\myexcel.xlsx" Set wbResults = Workbooks.Open(filename) ActiveWorkbook.RefreshAll wbResults.Close savechanges:=True End Sub

回答 6 投票 0

<code>Sub ReplaceLongText(ByRef doc As Word.Document, Optional ByVal k As Integer) </code>

Sub createPDFs() Dim wd As Word.Application Dim doc As Word.Document 'Ensure doc is Explicitly Declared as Word.Document Dim docPath As String Dim i As Integer ' Explicitly declare i as Integer ' Must Network Sharepoint site to computer to create a working path docPath = "C:\Users\obergmann\Project Sheet Generation/R&M_ProjectSheetTemplate.docx" Set wd = New Word.Application wd.Visible = True On Error GoTo ErrorHandler ' For loop to iteratively cycle through row numbers: For i = 8 To 10 ' Locate the template Set doc = wd.Documents.Open(docPath) ' Standard text replacements With wd.Selection.Find .Text = "<<Recommendation Number>>" .Replacement.Text = Cells(i, 1).Value .Execute Replace:=wdReplaceAll End With ' I have several more wd.Selection.Find after this ' Call the function to handle long text replacements Call ReplaceLongText(doc, i) ' Save the Word document Dim wordFileName As String wordFileName = ActiveWorkbook.Path & "\" & Cells(i, 2).Value & "_" & Cells(i, 1).Value & ".docx" doc.SaveAs2 fileName:=wordFileName, FileFormat:=wdFormatDocumentDefault ' export as pdf doc.ExportAsFixedFormat OutputFileName:=ActiveWorkbook.Path & "\" & Cells(i, 2).Value & "_" & Cells(i, 1).Value & ".pdf", _ ExportFormat:=wdExportFormatPDF Application.DisplayAlerts = False doc.Close SaveChanges:=False Next i wd.Quit Application.DisplayAlerts = True Exit Sub ErrorHandler: MsgBox "An error occurred: " & Err.description If Not doc Is Nothing Then doc.Close False If Not wd Is Nothing Then wd.Quit Application.DisplayAlerts = True End Sub Function SanitizeFileName(fileName As String) As String Dim invalidChars As String invalidChars = ":\/?*""<>|" Dim i As Integer For i = 1 To Len(invalidChars) fileName = Replace(fileName, Mid(invalidChars, i, 1), "_") Next i SanitizeFileName = fileName End Function `Then here is the next function: Sub ReplaceLongText(ByRef doc As Word.Document, Optional ByVal k As Integer) ' I think this is the line with issues Dim placeholders As Variant Dim columnIndices As Variant Dim description As String Dim chunkSize As Integer Dim startPos As Integer Dim chunk As String Dim j As Integer Dim rng As Range ' Create a range object ' Define placeholders and corresponding column indices placeholders = Array("<<Description>>", _ "<<Public Health & Safety - Compliance Driven Rationale>>", _ "<<Reliability & Resiliency Rationale>>", _ "<<Community Enrichment/Growth Rationale>>", _ "<<Financial Stewardship Rationale>>", _ "<<Efficiency, Modernization, & Environment Rationale>>", _ "<<Level of Service Rationale>>", _ "<<Additional Prioritization Notes>>", _ "<<Funding Source>>") columnIndices = Array(3, 12, 13, 14, 15, 16, 17, 18, 27) ' Corresponding Excel column numbers chunkSize = 255 ' Max characters per chunk ' Loop through all placeholders For j = LBound(placeholders) To UBound(placeholders) description = Cells(k, columnIndices(j)).Value startPos = 1 ' Set the range to search in the document Set rng = doc.Content With rng.Find .Text = placeholders(j) ' Set text to find .Forward = True .Wrap = wdFindStop ' Execute the search If .Execute Then ' Set range to the found text Set rng = doc.Range(rng.Start, rng.End) rng.Text = "" ' Clear only the placeholder text ' Insert text in chunks Do While startPos <= Len(description) chunk = Mid(description, startPos, chunkSize) rng.InsertAfter Text:=chunk startPos = startPos + chunkSize Loop End If End With Next j End Sub

回答 0 投票 0


回答 1 投票 0

回答 1 投票 0

使用ExcelVba

我需要监视某些网页的内容(以查看它们上发布的任何信息是否已更改)。由于各种原因,我必须使用Excel电子表格来做到这一点,因此这限制了我使用...

回答 0 投票 0

我有邮政编码替换问题ExcelVBA

MACRO需要替换一组将在C列中的邮政编码。对于其他邮政编码,将其替换为C列,并在C列的底部添加另一个邮政编码(1个邮政编码在列表上变成2个邮政编码)) 。

回答 1 投票 0

excel至MS Project

HiAM发现了可以在日期添加值的宏,但这需要为每个值手动编写。是否有更普遍的方法将Excel值传输到MS项目? https://i.sstat...

回答 1 投票 0


如何粘贴到excel中的隐藏板?

range(“ A1:Z9”)。选择 application.cutcopymode = false 选择 床单(“ Sheet2”)。选择 范围(“ A1”)。选择 selection.pastespecial糊状:= xlpastevalues,操作:=

回答 1 投票 0


我有一个带有多个枢轴表的工作表,每个枢轴表都有多个过滤器。

,从事工作表中的某些枢轴表在特定日期进行刷新。 例如“ 10/31/2023”

回答 0 投票 0

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.