急!汇入Excel调用宏生成柏拉图,有个问题,

hfy2003 2003-10-17 09:29:52
我的代码如下:为什么,我汇入EXcel生成的柏拉图,只有在vb运行(F5)被关闭时候才能被打开,当我运行vb程序(F5),生成柏拉图,只要程序在运行(F5),打开的已经保存的Exce文件是不完整的,只有眉头和尾,烦请各位大哥大姐解答,分不够可在加

Sub charu()
'
' charu エ栋
' fyhu  2003-10-16 魁籹エ栋
'

'
ActiveCell.FormulaR1C1 = "a"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "夹非"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("C3").Select
ActiveCell.FormulaR1C1 = "b"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "夹非"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("D3").Select
ActiveCell.FormulaR1C1 = "c"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "夹非"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("E3").Select
ActiveCell.FormulaR1C1 = "d"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "夹非"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("B4").Select
ActiveCell.FormulaR1C1 = "10"
Range("C4").Select
ActiveCell.FormulaR1C1 = "20"
Range("D4").Select
ActiveCell.FormulaR1C1 = "34"
Range("E4").Select
ActiveCell.FormulaR1C1 = "26"
Range("B3").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B3:E4")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
ActiveWindow.Visible = False
Windows("Report.xls").Activate
Range("H6").Select
ActiveSheet.ChartObjects("瓜 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
Windows("Report.xls").Activate
Range("K13").Select
ActiveSheet.ChartObjects("瓜 1").Activate
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("瓜 1").ScaleWidth 1.36, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("瓜 1").ScaleWidth 1.26, msoFalse, msoScaleFromBottomRight
End Sub

Private Sub Command1_Click()
Dim rs As ADODB.Recordset
Dim sql As String
sql = "select * from draw"
Set rs = conn.myconn.Execute(sql)
If rs.RecordCount > 0 Then
' MsgBox "OK"
Set TDBGrid1.DataSource = rs
Set DataGrid1.DataSource = rs

End If

End Sub

Private Sub Command2_Click()

Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Dim savepath As String
CommonDialog1.CancelError = True
On Error GoTo errhander
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.FileName = "Report"
CommonDialog1.DefaultExt = ".xls"
CommonDialog1.Filter = "Excel(*.xls)|*.xls|Text(*.txt)|*.txt"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = &H2
CommonDialog1.ShowSave

If Err.Number = cdlCancel Then
Exit Sub
End If

savepath = CommonDialog1.FileName

Set xlApp = CreateObject("excel.application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Add
On Error Resume Next
Set xlSheet = xlBook.Worksheets(1)

xlSheet.Cells(1, 1) = "aa"

Call charu


xlBook.SaveAs FileName:=savepath, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

xlBook.Saved = True
MsgBox "The Save is OK ", vbOKOnly, "Information"
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

errhander:
Exit Sub

Exit Sub






End Sub

...全文
84 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hfy2003 2003-10-17
  • 打赏
  • 举报
回复
怎么没有人来阿,小弟我很急哦,谢谢各位拉

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧