vb生成exe后运行时不能保存excel,点击保存后会让整个程序关闭,vb里面调试是可以运行的。有人能解决吗? 5
这是源代码DimxlAppAsExcel.ApplicationDimxlBookAsExcel.WorkbookDimsheetAsExcel.WorksheetPri...
这是源代码
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim sheet As Excel.Worksheet
Private Sub Command2_Click() '打开EXCEL过程
Dim mmm As String
mmm = Text1
Set xlApp = CreateObject("Excel.Application") '创建excel对象
xlApp.Visible = False '不显示打开的Excel
Set xlBook = xlApp.Workbooks.Add()
Set sheet = xlBook.Worksheets(1) '打开EXCEL工作表
sheet.Range("A1").Value = Label175.Caption
sheet.Range("B1").Value = Label176.Caption
sheet.Range("C1").Value = Label177.Caption
sheet.Range("D1").Value = Label178.Caption
sheet.Range("E1").Value = Label179.Caption
sheet.Range("F1").Value = Label180.Caption
sheet.Range("G1").Value = Label181.Caption
sheet.Range("H1").Value = Label182.Caption
sheet.Range("I1").Value = Label183.Caption
sheet.Range("J1").Value = Label184.Caption
sheet.Range("K1").Value = Label185.Caption
sheet.Range("L1").Value = Label186.Caption
sheet.Range("M1").Value = Label187.Caption
ActiveWorkbook.SaveAs ("C:\" & mmm)
xlBook.Close (True) '关闭并保存
xlApp.DisplayAlerts = False '关闭EXCEL不提示保存
xlApp.Quit '关闭EXCEL
Set xlBook = Nothing '释放设置的资源
Set sheet = Nothing
Set xlApp = Nothing
MsgBox "新建Excel工作表已保存到您的 C:\ 文件夹"
End Sub 展开
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim sheet As Excel.Worksheet
Private Sub Command2_Click() '打开EXCEL过程
Dim mmm As String
mmm = Text1
Set xlApp = CreateObject("Excel.Application") '创建excel对象
xlApp.Visible = False '不显示打开的Excel
Set xlBook = xlApp.Workbooks.Add()
Set sheet = xlBook.Worksheets(1) '打开EXCEL工作表
sheet.Range("A1").Value = Label175.Caption
sheet.Range("B1").Value = Label176.Caption
sheet.Range("C1").Value = Label177.Caption
sheet.Range("D1").Value = Label178.Caption
sheet.Range("E1").Value = Label179.Caption
sheet.Range("F1").Value = Label180.Caption
sheet.Range("G1").Value = Label181.Caption
sheet.Range("H1").Value = Label182.Caption
sheet.Range("I1").Value = Label183.Caption
sheet.Range("J1").Value = Label184.Caption
sheet.Range("K1").Value = Label185.Caption
sheet.Range("L1").Value = Label186.Caption
sheet.Range("M1").Value = Label187.Caption
ActiveWorkbook.SaveAs ("C:\" & mmm)
xlBook.Close (True) '关闭并保存
xlApp.DisplayAlerts = False '关闭EXCEL不提示保存
xlApp.Quit '关闭EXCEL
Set xlBook = Nothing '释放设置的资源
Set sheet = Nothing
Set xlApp = Nothing
MsgBox "新建Excel工作表已保存到您的 C:\ 文件夹"
End Sub 展开
展开全部
Shell "cmd.exe /c taskkill /f /im excel.exe", vbHide
如果你打开了多个EXCEL,即执行多次,如果不知道多少,可以判断进程是否存在再执行。
代码:
BACKENDP:
If CheckApplicationIsRun("EXCEL.exe") = True Then
Shell "cmd.exe /c taskkill /IM EXCEL.exe /F /T", vbHide
GoTo BACKENDP:
End If
如果你打开了多个EXCEL,即执行多次,如果不知道多少,可以判断进程是否存在再执行。
代码:
BACKENDP:
If CheckApplicationIsRun("EXCEL.exe") = True Then
Shell "cmd.exe /c taskkill /IM EXCEL.exe /F /T", vbHide
GoTo BACKENDP:
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |