VB中怎么把EXCEL表另存

DimXlAppAsNewExcel.ApplicationDimxlBookAsNewExcel.WorkbookDimxlSheetAsNewExcel.Worksh... Dim XlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Set xlBook = XlApp.Workbooks.Open("C:\SSS.xls")
XlApp.Visible = False
Set xlSheet = xlBook.Sheets("sheet1")
xlSheet.Select

xlSheet.Range("c4") = Text1.Text
xlSheet.Range("c7") = Text2.Text
xlSheet.Range("c5") = Text3.Text
xlSheet.Range("i10") = Text5.Text

xlBook.Save 这里现在是保存,但是我想要点击command的时候,会自动弹出一个提示另存的对话 框,并且可以选择具体另存的路径和保存名称,就和excel表格另存是一样,有没有具体代码,谢谢 Set Sheet = Nothing
Set xlBook = Nothing
XlApp.Quit
Set XlApp = Nothing
展开
 我来答
小胡子话娱乐
推荐于2016-11-09 · TA获得超过6051个赞
知道大有可为答主
回答量:7899
采纳率:0%
帮助的人:3252万
展开全部
Public Sub FileSave() '保存文档
'/*数据输出到Excel
On Error GoTo Err_Proc
Dim xlApp As Object 'Excel.Application
Dim xlBook As Object 'Excel.Workbook
Dim xlSheet As Object 'Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Sheets(1)
dff.CommonDialog1.Filter = "Microsoft Excel 工作簿|*.xls|文本文件(*. txt)|*.txt|所有文件(*.*)|*.*"
dff.CommonDialog1.FileName = ".xls"
dff.CommonDialog1.InitDir = "D:"
dff.CommonDialog1.ShowSaveAs
With dff.MSFlexGrid1
'/*设置列宽
For j = 0 To .Cols - 1
xlSheet.Columns(j + 1).ColumnWidth = .ColWidth(j) / 100
Next j
For I = 0 To .Rows - 1
For j = 0 To .Cols - 1
xlSheet.Cells(I + 1, j + 1).Value = " " & .TextMatrix(I, j)
Next j
Next I
End With
xlSheet.SaveAs (dff.CommonDialog1.FileName)
xlBook.Close
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlApp = Nothing
flag8 = 1
Call PutWindowNoOnTop(dff)
MsgBox "计算结果已成功保存!", 0 + vbInformation, "提示"
Exit Sub
Err_Proc:
flag8 = 0
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlApp = Nothing
Call PutWindowNoOnTop(dff)
MsgBox "您已取消保存!", vbExclamation, "提示"
Call PutWindowOnTop(dff)
End Sub

Public Sub FileOpen() '打开文档
'/Excel数据输出到Msflexgrid表格
On Error GoTo Err_Proc
Dim iRows As Integer
Dim iCols As Integer
Dim objExcel As excel.Application
Dim objWorkBook As excel.Workbook
Dim objSheet As excel.Worksheet
Dim objRange As excel.Range
Dim sFile As String
dff.CommonDialog1.Filter = "Microsoft Excel 工作簿|*.xls|文本文件(*. txt)|*.txt|所有文件(*.*)|*.*"
dff.CommonDialog1.FileName = ".xls"
dff.CommonDialog1.InitDir = "D:"
dff.CommonDialog1.ShowOpen
Set objExcel = New excel.Application
Set objWorkBook = objExcel.Workbooks.Open(dff.CommonDialog1.FileName)
Set objSheet = objWorkBook.ActiveSheet
Set objRange = objSheet.UsedRange
iRows = objRange.Rows.Count
iCols = objRange.Columns.Count
dff.MSFlexGrid1.Rows = iRows
dff.MSFlexGrid1.Cols = iCols
For I = 0 To iRows - 1
dff.MSFlexGrid1.RowHeight(I) = 500
Next I
For I = 0 To iCols - 1
dff.MSFlexGrid1.ColWidth(I) = dff.MSFlexGrid1.Width / 4 - 100
dff.MSFlexGrid1.ColAlignment(I) = flexAlignCenterCenter
Next I '输出数据
For I = 1 To iRows
For j = 1 To iCols
dff.MSFlexGrid1.TextMatrix(I - 1, j - 1) = objSheet.Cells(I, j)
Next j
Next I
objWorkBook.Close
Set objExcel = Nothing
Set objWorkBook = Nothing
Set objSheet = Nothing
flag8 = 1
Exit Sub
Err_Proc:
Set objExcel = Nothing
Set objWorkBook = Nothing
Set objSheet = Nothing
flag8 = 0
Call PutWindowOnTop(dff)
End Sub
泉汇泽
2014-06-12 · TA获得超过423个赞
知道小有建树答主
回答量:763
采纳率:0%
帮助的人:314万
展开全部
  
xlBook.SaveAs Filename:= "C:\Users\Administrator\Desktop\dfaddsasdaaaa.xls"

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
真真真白丁
推荐于2016-01-11 · TA获得超过8517个赞
知道大有可为答主
回答量:4644
采纳率:85%
帮助的人:1691万
展开全部
亲,试一下这个吧:
XlApp.Dialogs(5).Show
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ExcelOffice
2014-06-12 · TA获得超过570个赞
知道小有建树答主
回答量:1583
采纳率:0%
帮助的人:734万
展开全部
试试
xlBook.SaveAs
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式