本帖最后由 hong90342 于 2025-12-12 11:09 编辑
VBA使用工具栏自定义按钮打开Word
版本:企业版V9.89
- Imports SpreadsheetGear
- Imports KbInterfaces
- Imports System.Windows.Resources
- Imports System.Windows.Threading
- Imports System.Windows
- Imports System.Windows.Controls
- Imports C1.Silverlight
- Imports C1.Silverlight.C1MessageBoxButton
- Imports C1.Silverlight.C1MessageBoxIcon
- Imports Newtonsoft.Json
- Imports Newtonsoft.Json.Linq
- Imports System.IO
- Imports System.Text
- Imports System.Runtime.InteropServices.Automation
- Namespace ExcelViewVBDotnet
- Public Class StandardInterface
- Dim btnName As String = ""
- Dim CF As TextBox, VW As Object
- Dim TS As StackPanel
- Dim EV As SpreadsheetGear.Windows.Controls.WorkbookView, AW As SpreadsheetGear.IWorkbook, Range As SpreadsheetGear.IRange
- Public Sub Workbook_Open(OldRoot As Object, NewRoot As Object, Excel As SpreadsheetGear.Windows.Controls.WorkbookView)
- EV = Excel
- Excel.GetLock()
- AW = Excel.ActiveWorkbook
- Range = AW.ActiveWorksheet.Range
- Excel.ReleaseLock()
- Dim click As Action(Of String) = Function(other)
- Call InsertTableRows()
- End Function
- App.KBAddButton(17, "msg", "生成", click)
- '-----------------------------------------------------------------------------------------------------------------------------
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object, e As SpreadsheetGear.Windows.Controls.RangeSelectionChangedEventArgs)
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object, e As SpreadsheetGear.Windows.Controls.RangeChangedEventArgs)
- End Sub'单元格编辑完成后执行事件
- Public Sub ButtunClick(sender As Object, e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
- End Sub '暂不支持
- Sub InsertTableRows()
- Dim _word As Object = AutomationFactory.CreateObject("Word.Application")
- _word.visible = True
- _word.Documents.open("d:\word\demo.docx")'ActiveDocument
- ActiveWorkbook.WorkbookSet.GetLock()
复制代码
|
|
hong90342