乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > Mac <em>Excel</em> <em>VBA</em> 2011

Mac <em>Excel</em> <em>VBA</em> 2011

作者:乔山办公网日期:

返回目录:excel表格制作


不会弹出zhidao对话框吧。代码可简化一下:
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '允许用户选择一个文件夹
fd.InitialFileName = "\\PIC\2015\" '定义默认路

不需要引入任e79fa5e98193e78988e69d83365何库,直接从application调用
Option Explicit
Private Sub CommandButton1_Click()

Dim directory As String, fileName As String, sheet As Worksheet, total As Integer
Dim fd As Office.FileDialog

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
.AllowMultiSelect = False
.Title = "Please select the file."
.Filters.Clear
.Filters.Add "Excel 2003", "*.xls?"

If .Show = True Then
fileName = Dir(.SelectedItems(1))

End If
End With

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Workbooks.Open (fileName)

For Each sheet In Workbooks(fileName).Worksheets
total = Workbooks("import-sheets.xlsm").Worksheets.Count
Workbooks(fileName).Worksheets(sheet.Name).Copy _
after:=Workbooks("import-sheets.xlsm").Worksheets(total)
Next sheet

Workbooks(fileName).Close

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
Sub 打开()
With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = True
    .Filters.Add "文本件", "*.txt", 1
    .InitialFileName = "g:\123\"
    .InitialView = msoFileDialogViewDetails
    .Title = "打开"
    If .Show = 0 Then Exit Sub
    Filename = .SelectedItems(1)
End With
Shell "notepad " & Filename, vbNormalFocus
End Sub


不需要引入任何对象:

使用 FileDialog对象
使用 FileDialog属性返回一个 FileDialog对象。FileDialog属性位于每个单独 Office 应用程序的 Application对象中。该属性使用一个参数 DialogType 确定该属性返回的 FileDialog对象类型。FileDialog对象有四种类型:
“打开”对话框:让用户选择一个或多个可以在主机应用程序中使用 Execute方法打开的文件。
“另存为”对话框:让用户选择一个可以使用 Execute方法保存当前文件的文件。
“文件选取器”对话框:让用户选择一个或多个文件。用户选择的文件路e69da5e6ba90e799bee5baa6e997aee7ad94361径将捕获到 FileDialogSelectedItems集合。
“文件夹选取器”对话框:让用户选择一个路径。用户选择的文件路径将捕获到 FileDialogSelectedItems集合。
每个主机应用程序只能实现一个 FileDialog对象实例。因此,在创建多个 FileDialog对象时将延续 FileDialog对象的很多属性。所以,在显示对话框之前请确保已经针对用途正确设置了所有属性。
要使用 FileDialog对象显示一个对话框,必须使用 Show方法。对话框显示后,在用户消除对话框之前将不执行任何代码。本示例创建并显示“文件选取器”对话框,并在消息框中显示每个选定的文件。

Sub Main()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example simply displays the path in a message box.
MsgBox "The path is: " & vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub

相关阅读

  • Mac <em>Excel</em> <em>VBA</em> 2011

  • 乔山办公网excel表格制作
  • 不会弹出zhidao对话框吧。代码可简化一下:Set fd = Application.FileDialog(msoFileDialogFolderPicker) 允许用专户选择一个文件夹fd.InitialFileName = "PIC2015" 定义默认路属径vba中filedialog.ite
  • 销售月报表模板急用

  • 乔山办公网excel表格制作
  • 一般只要你税没有报错的话 你的库存有影响的话你自己把帐调平就可以的 无需太过自责和担心的 你可以跟统计局的人员说明情况 事情发生总有弥补的余地的 那你让记账公司帮你调账
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网