宏 - 打开文件夹中的所有文件 [英] macro - open all files in a folder

查看:282
本文介绍了宏 - 打开文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开指定文件夹中的所有文件,并具有以下代码

I want to open all files in a specified folder and have the following code

Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "\\ILAFILESERVER\Public\Documents\Renewable Energy\FiTs\1 Planning
           Department\Marks Tracker\Quality Control Reports"
MyFile = Dir(MyFolder & "\*.xlsx")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
Loop
End Sub

我遇到的问题是它只是保持尝试重复打开文件夹中的第一个文件,并且不会继续。任何人都可以帮忙,我是VBA的一个新手,可以帮助一些。我试图打开大约30个都是.xlsx格式的报告。非常感谢您提前。

The problem I have is that it just keeps trying to open the first file in the folder repeatedly and won't move on. Can anybody help, I'm a bit of a novice at VBA and could really do with some assistance. I'm trying to open around 30 reports that are all in .xlsx format. Many thanks in advance.

推荐答案

您必须在循环之前添加此行

    MyFile = Dir
Loop

这篇关于宏 - 打开文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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