當前位置:首頁 » 知網查重 » vba打開目錄

vba打開目錄

發布時間: 2021-03-19 06:07:27

① vba打開文件後如何獲得打開文件的路徑

S=activeworkbook.Path & "\" & activeworkbook.Name

S=workbooks("test.xls").Path & "\" & workbooks("test.xls").Name

② excel運用VBA打開文件夾並搜索打開文件:

Dim c As Worksheet, addr As String, cou As Integer, coun As Integer
Dim path As String, str As String, actsh As Worksheet, keyword As String, i As Integer
Dim fil As String
path = InputBox("Please input the folder path of excel file need combine")
'or path="\\svr001\公用文檔"
keyword = activecell.value
If InStr(1, path, ":") < 1 And InStr(1, path, "\\") < 1 Then GoTo ne
If Right(path, 1) = "\" Then path = left(path, Len(path) - 1)
If Len(Trim(keyword)) < 1 Then GoTo ne
cou = 0
Application.ScreenUpdating = False
With Application.FileSearch
.LookIn = path
.FileName = "*" & keyword & "*.xls"
If .Execute > 0 Then
coun = .FoundFiles.count
For i = 1 To coun
Workbooks.Open (.FoundFiles(i))
Next i
End If
End With
Range("A1:A2").EntireRow.Delete
Application.ScreenUpdating = True
MsgBox ("Total processed " & cou & " files!")
ne:
End Sub

③ EXCEL如何使用VBA打開相對路徑下的文件或文件夾

打開文件如下:

Workbooks.Open ("C:對賬單對帳單.xlsx")

這里你可以把「C:對賬單」換成你的絕對路徑,

你可以用:a = ThisWorkbook.Path

a = ThisWorkbook.Path

Workbooks.Open ("" & a & "&" "&對帳單.xlsx")

來獲取你當前表的絕對路徑,然後再打開,因為不知道你的具體情況,如果有問題可以hai我

如果當前文件夾下還有A文件夾可以用代碼:

Workbooks.Open ("" & a & "&" A"&b.xlsx")

④ VBA中如何打開一個文件夾內的所有EXCEL文件

'這段代碼是讀取一個文件夾下的所有文件,也可以根據擴展名篩選其它格式的.
'有了文件名,就是打開文件,獲得每個文件的SHEET名字.然後寫到你想要的地方
Sub
Macro1()
Dim
myDialog
As
FileDialog,
oFile
As
Object,
strName
As
String,
n
As
Integer
Dim
FSO
As
Object,
myFolder
As
Object,
myFiles
As
Object
,Dim
fn$
Set
myDialog
=
Application.FileDialog(msoFileDialogFolderPicker)
n
=
1
With
myDialog
If
.Show
<>
-1
Then
Exit
Sub
Set
FSO
=
CreateObject("Scripting.FileSystemObject")
'這是文件夾選擇,點選到你存放文件的那個
Set
myFolder
=
FSO.GetFolder(.InitialFileName)
Set
myFiles
=
myFolder.Files
For
Each
oFile
In
myFiles
strName
=
UCase(oFile.Name)
strName
=
VBA.Right(strName,
3)
If
strName
=
"xls"
Or
strName
=
"XLS"
Then
'這是擴展名選擇
'下面就可接著寫打開文件讀取數據再寫入的語句了,如下:
fn
=
myFolder
&
"\"
&
oFile.Name
Workbooks.Open
Filename:=fn
Worksheets(1).Select
'假設你讀取SHEET1的數據
RANGE_
=
Range("A2:F50")
'需要數據的區域,自己修改
Windows("外部表格數據自動導入.xls").Activate
'這個是新表的文件名,自己修改下
Worksheets(n).Select
'打開第幾個文件就選擇SHEET幾,如果沒有可用ADD代碼添加
Range("a2:f5")
=
RANGE_
'寫入數據
Workbooks(2).Close
n
=
n
+
1
End
If
Next
End
With
End
Sub
查看原帖>>

⑤ 關於Excel VBA打開文件夾

Sub openmyexcel()
Dim fs, f, i, j, k, f1, f2
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("f:\hk")
For Each i In f.subfolders
If InStr(i.Name, "102471") <> 0 Then

Set f1 = fs.getfolder(i.Path)
For Each j In f1.subfolders
If InStr(j.Name, "prem") <> 0 Then

Set f2 = fs.getfolder(j.Path)
For Each k In f2.Files
If InStr(k.Name, "00") <> 0 Then
Workbooks.Open (k.Path)
Set f2 = Nothing
Exit For
End If
Next
Set f1 = Nothing
Exit For
End If
Next
Set f = Nothing
Exit For
End If
Next
End Sub
————————————————————————————
在thisworkbook中執行

⑥ EXCEL vba 打開上級目錄文件

Sub test()
p = ThisWorkbook.Path
p = Mid(p, 1, InStrRev(p, "\"))
Debug.Print p
End Sub

⑦ vba 打開指定路徑的文件

打開文件一般是用Open語句的
Open "C:\1.txt" for input As #1
........
Close #1

⑧ VBA 怎麼打開當前文件夾下的excel

你只要運行語句,抄然後找到你那個文襲件夾,Office下次再打開是會自動記錄位置的,直接定位到那個文件夾。
而且要指出的是:
GetOpenFilename 方法:顯示標準的「打開」對話框,並獲取用戶文件名,而沒有真正打開任何文件。
要真正打開文件要使用:Workbook的Open方法
xlapp.Workbooks.Open (Filename)
注意:其中Filename參數需要指定文件的全路徑。

熱點內容
塗鴉論文 發布:2021-03-31 13:04:48 瀏覽:698
手機資料庫應用 發布:2021-03-31 13:04:28 瀏覽:353
版面217 發布:2021-03-31 13:04:18 瀏覽:587
知網不查的資源 發布:2021-03-31 13:03:43 瀏覽:713
基金贖回參考 發布:2021-03-31 13:02:08 瀏覽:489
懸疑故事範文 發布:2021-03-31 13:02:07 瀏覽:87
做簡單的自我介紹範文 發布:2021-03-31 13:01:48 瀏覽:537
戰略地圖參考 發布:2021-03-31 13:01:09 瀏覽:463
收支模板 發布:2021-03-31 13:00:43 瀏覽:17
電氣學術會議 發布:2021-03-31 13:00:32 瀏覽:731