如何允许用户从VBA中的特定位置打开文件?

时间:2017-07-13 23:31:36

标签: excel vba excel-vba

我已经想出了如何打开浏览选项以允许用户选择他们希望稍后在代码中打开的文件,但我希望浏览自动打开文件所在的特定文件夹。

我该怎么做?目前默认打开我的Documents文件夹,我想打开代码"S/:CHEM Reports".

这是我到目前为止所尝试的......

spec_chems = Application.GetOpenFilename(Title:="Specialty Chems")
If spch = False Then End
Set spch = Application.Workbooks.Open(spec_chems)
With spch
    .AllowMultiSelect = False
    .InitialFileName = "S:\CHEM Reports"
    .Activate
End With

2 个答案:

答案 0 :(得分:1)

在调用对话框之前更改当前目录:

PImage[] reverseRun = new PImage [16];

PImage[] zeroArray = new PImage [16];

void setup(){
  size(800,600);
  //Right Facing
  for(int i = 0; i < zeroArray.length; i++){
    zeroArray[i] = loadImage (i + ".png");
    zeroArray[i].resize(155,155);
    }
  //Left Facing
  for( int z = 0; z < reverseRun.length; z++){
    reverseRun[z] = loadImage ( "mirror" + z + ".png");
    reverseRun[z].resize(155,155);
    }
  }

void draw(){
  frameRate(15);
  background(255);
  imageMode(CENTER);

  if(x > width+10){
    x = 0;
  } else if (x < - 10){
    x = width;}






if (i >= zeroArray.length){
  i  = 3;} //looping to generate constant motiion 

if ( z >= reverseRun.length){
    z = 3;} //looping to generate constant motiion 

if (isRight) {
     image(zeroArray[i], x, 300);
     i++;
  } //going through the images at the array
else if (isLeft) {
     image(reverseRun[z],x,300);
     z++;
  } going through the images at the array

else if(!isRight){
     image(zeroArray[i], x, 300);
     i = 0; } //"stoped" sprite
  }
}




 //movement
float x = 300;
float y  = 300;
float i = 0;
float z = 0;
float speed = 25;
boolean isLeft, isRight, isUp, isDown; 
void keyPressed() {




setMove(keyCode, true);

 if (isLeft ){
   x -= speed;
 }
 if(isRight){
   x += speed;
 }
}

void keyReleased() {
  setMove(keyCode, false);

}

boolean setMove(int k, boolean b) {
  switch (k) {
  case UP:
    return isUp = b;

  case DOWN:
    return isDown = b;

  case LEFT:
    return isLeft = b;

  case RIGHT:
    return isRight = b;

  default:
    return b;  }
}  

答案 1 :(得分:0)

我经常将字符串变量定义为文件路径,然后将文件路径与我要打开的文件连接起来。我还可以将其他工作簿保存到我定义的文件路径中。

    fPath = "C:\Users\myusername\Desktop\Helpothers"
    sourcefname = fPath & "\" & fileID & ".xlsx"
    Application.Workbooks.Open (sourcefname)

fileID是我要打开的文件的名称。