VBA Excel提示用户选择默认文件夹中的文件

时间:2015-05-29 07:19:29

标签: vba excel-vba directory default excel

我想提示用户在默认文件夹中打开Excel文件。我不知道如何打开默认文件夹。

Sub Program1()
    DefaultFolder = "C:\user\dump"
    FName = Application.GetOpenFilename
    If FName <> False Then
        Set WorkB2 = Workbooks.Open(FName)
        ' some codes here
    End If
End Sub                           

2 个答案:

答案 0 :(得分:7)

使用chdir:

Sub Program1()
  Chdir "C:\user\dump"
  FName = Application.GetOpenFilename
  If FName <> False Then
    Set WorkB2 = Workbooks.Open(FName)
    ' some codes here
  End If
End Sub

答案 1 :(得分:1)

以下是打开Excel文件的示例

var app = angular.module('my-app', [
    'ui.router',
    'ngAnimate'
]);

// ...

app.run(function ($rootScope, navigationService) {

    $rootScope.handleEvt = function(e) {
        if ($rootScope.navVisible) {
            switch (e.which) {
                // right
                case 37:
                    $rootScope.navDirection = "right";
                    navigationService.navigate(navigationService.getCurrentPageIndex() - 1);
                    break;
                // left
                case 39:
                    $rootScope.navDirection = "left";
                    navigationService.navigate(navigationService.getCurrentPageIndex() + 1);
                    break;
            }
        }
    };

// ...