循环文件以设置大纲级别 [英] Loop Through Files To Set Outline Level

查看:110
本文介绍了循环文件以设置大纲级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此VBA仅记录两行,打开文件并设置大纲级别。第一个块工作。除文件名外,第二个版本不相同。这只是三个文件的测试运行,以检查outline命令。


我必须循环访问59个文件,并且仍然在研究如何做到这一点,并希望得到任何帮助也好。


Sub Macro8()
$
'宏观宏8

'宏记录21/07/18 11:09作者Trevor。


FileOpenEx名称:=" X:\ 5000 Series Jobs \ 51414-177.mpp",FormatID:=" MSProject.MPP"

OutlineShowTasks OutlineNumber:= pjTaskOutlineShowLevel1
$
FileSave

FileCloseEx



FileOpenEx名称: =" X:\ 5000 Series Jobs \ 51414-178.mpp",FormatID:=" MSProject.MPP"

OutlineShowTasks OutlineNumber:= pjTaskOutlineShowLevel1p

FileSave

FileCloseEx



FileOpenEx名称:=" X:\5000系列作业\ 51414-180.mpp",FormatID:= " MSProject.MPP"

OutlineShowTasks OutlineNumber:= pjTaskOutlineShowLevel1p

FileSave
FileCloseEx

解决方案

嗨Trevor,


欢迎来到vba!


不知道是怎么回事,但字母"p"附加到第2次和第3次尝试的OutlineShowTasks行。 这会导致错误。


如果你的59个文件名确实按照数字递增,那么循环遍历它们可能就像这样简单:


 

 Sub Macro2()
On Error Resume Next'这会忽略丢失文件等错误。

Dim Filename As String
Dim Filenameseq As Long

For Filenameseq = 177 To 240
Filename =" X:\ * 5000 Series Jobs \ 51414-" &安培; Filenameseq& " .MPP"
FileOpenEx Name:= Filename,FormatID:=" MSProject.MPP"
OutlineShowTasks OutlineNumber:= pjTaskOutlineShowLevel1
FileSave
FileCloseEx
Next Filenameseq

End Sub




This VBA is from recording just two lines, opening the file and setting the outline level. The first chunk works. The second one doesn't even though it is identical except for the file name. This is just a test run for three files to check the outline command.

I have to loop through 59 files, and still working on how to do that, and would appreciate any help with that too.

Sub Macro8()
' Macro Macro8
' Macro Recorded 21/07/18 11:09 by Trevor.

FileOpenEx Name:="X:\5000 Series Jobs\5142-177.mpp", FormatID:="MSProject.MPP"
OutlineShowTasks OutlineNumber:=pjTaskOutlineShowLevel1
FileSave
FileCloseEx

FileOpenEx Name:="X:\5000 Series Jobs\5142-178.mpp", FormatID:="MSProject.MPP"
OutlineShowTasks OutlineNumber:=pjTaskOutlineShowLevel1p
FileSave
FileCloseEx

FileOpenEx Name:="X:\5000 Series Jobs\5142-180.mpp", FormatID:="MSProject.MPP"
OutlineShowTasks OutlineNumber:=pjTaskOutlineShowLevel1p
FileSave
FileCloseEx

解决方案

Hi Trevor,

Welcome to vba!

Don't know how it happened, but the letter "p" got appended to the OutlineShowTasks lines of your 2nd and 3rd try.  That causes the error.

If your 59 filenames are indeed numerically incremented as shown, then looping through them may be as simple as something like this:

 

Sub Macro2()
    On Error Resume Next 'This ignores errors like missing files etc.
    
    Dim Filename As String
    Dim Filenameseq As Long
    
    For Filenameseq = 177 To 240
        Filename = "X:\5000 Series Jobs\5142-" & Filenameseq & ".mpp"
        FileOpenEx Name:=Filename, FormatID:="MSProject.MPP"
        OutlineShowTasks OutlineNumber:=pjTaskOutlineShowLevel1
        FileSave
        FileCloseEx
    Next Filenameseq
    
End Sub



这篇关于循环文件以设置大纲级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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