VBA请参阅工作表与图表表

VBA请参阅工作表与图表表

本文介绍了VBA请参阅工作表与图表表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图写一个小的函数,它接受一个文件路径(工作簿保存在其中),targetpath(pdf将被保存到)和一个选项卡名称的字符串(管道(|)分隔) in excel。I'm trying to write a small function that takes in a filepath (where the workbook was saved at), targetpath (where the pdf will be saved to), and a string of tab names (pipe (|) delimited) in excel.函数的用户不必输入标签名称的字符串(它是可选的),如果没有,我想选择所有的可见选项卡并打印它们。如果用户在单独的工作表中有50个图表,并且不想写如Chart1 | Chart2 | ....的字符串,则会是这种情况。The user of the function doesn't have to input a string of tab names (it's optional) and if they don't, I want to select all of the visible tabs and print them. This would be in the case if the user has 50 charts in separate worksheets and don't want to write a string like "Chart1|Chart2|...."代码:For Each WSO.Name In WBO.Worksheets strSheets = strSheets & WSO.Name & "|"Next WSOstrSheets = Left(strSheets, Len(strSheets) - 1)arraySheets() = Split(strSheets, "|")WBO.Sheets(arraySheets()).SelectWBO.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _ strFilePath, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ True循环:它不抓取任何工作表,如Chart1,它只抓取工作表,如Sheet1。此外,它会抓取隐藏的工作表,以便当我尝试选择它们时,我得到一个超出界限的错误。There's two problems with the For Each loop: it doesn't grab any sheets such as "Chart1", it only grabs sheets such as "Sheet1". Also, it will grab hidden sheets so that when I try to select them all I get an out of bounds error.我不知道是否引用图表表I didn't know if a Chart sheet is referred to differently then a regular sheet or why hidden sheets are also chosen.推荐答案使用 WBO.SheetsUse WBO.Sheets instead of WBO.Worksheets in the loop.验证 这篇关于VBA请参阅工作表与图表表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 17:36