在VB里怎样控制Excel的字体和颜色
1个回答
展开全部
'发送消息函数 (SendMessage)
Public Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'查找窗体名函数 (SendMessage)
Public Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Function myExcelOpen(MyExcelAddress As String, Mysheet As String, MyCaption As String) '打开Excel文件函数 MyExcelAddress 路径下的Excel文件
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
MyWinHwnd = FindWindow(vbNullString, MyCaption) '调用FindWindow api 函数 "查找" 适合条件的窗口
If MyWinHwnd <> 0 Then
MsgBox "文件已经打开"
SetForegroundWindow MyWinHwnd '设置为活动窗口
SendMessage MyWinHwnd, SW_SHOWMAXIMIZED, 0, 0
Exit Function
Else
Set xlBook = xlApp.Workbooks.Open(MyExcelAddress) '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlSheet = xlBook.Worksheets(Mysheet) '设置活动工作表
xlBook.Worksheets(Mysheet).Select
End If
End Function
Private Sub Command1_Click()
On Error Resume Next
myExcelOpen App.Path & "\班组标准化建设\2.标准化作业管理\6.派工单\派工单.xls", _
"派工单", "Microsoft Excel - 派工单.xls"
xlBook.Worksheets("派工单").Range(1,2).Font.ColorIndex = 3
xlBook.Worksheets("派工单").Range(1,2).FontName = "宋体"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询