Dim newxls As New Excel. Application
CommonDialog1. FileName=""
Dim I, r, c As Integer
'Set xlApp=CreateObject (" Excel. Application ")' create Excel object
'statement application object
The Set newxls=CreateObject (" Excel. Application ") 'create Excel object
Dim newbook As New Excel. The Workbook
Dim newsheet As New Excel. The Worksheet
The Set newbook=newxls. Workbooks. Add 'create work thin
Set newsheet=newbook. Worksheets (1) 'create work table
'20140429 change
Newsheet. Activate 'activation
With CommonDialog1
. CancelError=False 'in the dialog box, press the cancel button is not an error
The Flags=cdlOFNHideReadOnly & amp; CdlOFNOverwritePrompt
. The Filter="Excel Files (*. XLSX) | *. XLSX" 'at the bottom of the dialog box "file type" drop-down quantico displays the contents of the "
. FilterIndex=1 "choose" save the type "the first value is the default value, namely" Excel Files (*. XLS) | *. XLS "
. ShowSave
'set the Excel format the content, now temporarily not
'With newsheet
'. The Cells. The Font. The Name="System"
. '. The Cells. The Font Size=12
'Name="data list
"'
'Range (Cells (1, 1), Cells (1, DataGrid1. Columns. The Count)). Select
'Selection. The HorizontalAlignment=xlCenter
'Selection. VerticalAlignment=xlCenter
'Selection. The Merge' merging center
'Cells (1, 1)="export excel file
"End With
'if the input file name is empty, to click on the cancel button
If CommonDialog1. FileName="" Then
Newbook. RunAutoMacros (xlAutoClose) 'close the macro
Newbook. Close (True)
Newxls. Quit
The Exit Sub
End the If
Me. TxtMessage. Visible=True
Dim sum1 As String
Dim sum2 As String
'Dim Peg As Float
If rsPE. RecordCount & gt; 0 Then
For I=0 To DataGrid1. 'circulation add header Columns. The Count - 1
Newsheet. Cells (32, I + 1)=DataGrid1. Columns (I). The Caption
Next
RsPE. MoveFirst
Do Until rsPE. EOF
R=rsPE. AbsolutePosition 'read you object position the current record number
For c=0 To DataGrid1. Columns. The Count - 1
DataGrid1, Col=c 'read c column data
'turn text type numeric type value
'newsheet. Cells (r + 32, c + 1). The NumberFormatLocal="0 _
"
'the SendKeys "{F2}
"'the SendKeys "{enter}
"If r=0 Or c=0 Then
Newsheet. Cells (r + 32, c + 1)=DataGrid1. Columns (c)
The Else
Newsheet. Cells (r + 32, c + 1)=Val (DataGrid1. Columns (c))
'the Debug. Print newsheet. Cells (R + 32, 2)
'Sum1=Sum1 + newsheet. Cells (r + 32, 2)
'Sum2=Sum2 + newsheet. Cells (r + 32, 3)
End the If
If Len (Me) txtMessage) Text) & lt; 16 Then=
Me. TxtMessage. Text=Me. TxtMessage. Text + ", "
The Else
Me. TxtMessage. Text="data loading, please later!"
End the If
Next
RsPE. MoveNext
Loop
End the If
ExcelFileName=CommonDialog1. FileName
'the rs lines
ExcelRol=rsPE. RecordCount
The number of columns' rs
ExcelRow=DataGrid1. Columns. The Count
'Dim GR As Integer
'With Me. DataGrid1
'For GR=0 To ExcelRol - 1
'Row=GR
'Col=1
'
'sum1=sum1 + Val (. Text)
'Next GR
'End With
'the Debug. Print sum1
'Dim GC As Integer
'With Me. DataGrid1
'For GC=0 To ExcelRol - 1
'Row=GC
'Col=2
'sum2=sum2 + Val (. Text)
'Next GC
'End With
'the Debug. Print sum2
Dim LastRange As String
'at the bottom right Sheet page number
LastRange=getExcelColName (ExcelRow)
'form of English, for example: "Sheet1! $A $32: $$41 CM "
Dim RangeEN As String
RangeEN="Sheet1! $A $32: $" + fristWord + SecondWord + "$" + CStr (32 + ExcelRol)
The Debug. Print RangeEN
With newsheet
Cells (1, 1)="current weekly:" + WeekStr
Cells (1, 1). The Font. Color=- 16776961
Cells (1, 1). The Font. The Size=18
'Cells (2, 1)="human capacity proportion:" + CStr (Round (Val (sum2/sum1), 2) * 100) + "%
"
Cells (2, 1). The Font. The Size=18
'Cells (2, 3)=Round (Val (Sum2/Sum1), 2) * 100 & amp; "%", "
'Cells (2, 3). The Font, Size=18
'Cells (2, 3). The Font, Color=- 16776961
'20140429 change
'the selected area
Range (Cells (32, 1). The Address, Cells (32 + ExcelRol, ExcelRow). The Address). Select
With Selection
ActiveSheet. Shapes. AddChart. Select
ActiveChart. SetSourceData Source:=newsheet Range (RangeEN)
ActiveChart. ChartType=xlColumnStacked
ActiveWindow. ScrollColumn=1
Chart ActiveSheet. ChartObjects (" 1 "). Activate
The left=20
Top=70
Chart ActiveSheet. Shapes (" 1 "). 3.7 ScaleWidth, msoFalse, msoScaleFromTopLeft
Chart ActiveSheet. Shapes (" 1 "). 1.3, ScaleHeight msoFalse, msoScaleFromTopLeft
End With
Chart ActiveSheet. ChartObjects (" 1 "). Activate
ActiveChart. ChartArea. Select
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
'sum1="=SUM (B33: B" + CStr ((33 + ExcelRol - 1)) + ") "
'sum2="=SUM (C 33: C" + CStr ((33 + ExcelRol - 1)) + ") "
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull