打开文件而不调用文件路径 [英] Open File Without Calling Filepath

查看:75
本文介绍了打开文件而不调用文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用excel VBA.我想按下一个按钮,直接打开另一个文件,而没有选择文件窗口"的作用.

I'm using excel VBA. I want to press a button that opens another file directly without the effect of "choosing file window".

这是当前代码:

Sub loadFile_click()
Workbooks.Open("C:\Users\GIL\Desktop\ObsReportExcelWorkbook.xlsx")
End Sub

在这种情况下,文件与主文件位于同一文件夹中.

In this case, the file is in the same folder as the main file.

有没有办法输入文件的路径?

Is there any way to do it without entering the file's path?

推荐答案

如果文件名是固定的,则可以使用ActiveWorkbook.Path函数返回当前工作簿的路径:

If the file name is fixed you can use the ActiveWorkbook.Path function to return the path of the current workbook:

Dim FileName as string FileName = ActiveWorkbook.Path & "\myfile.xlsx

Dim FileName as string FileName = ActiveWorkbook.Path & "\myfile.xlsx

检查是否需要该额外的斜杠字符.

Check if you need that extra slash character.

这篇关于打开文件而不调用文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆