excel - 保持工作表的页面方向
问题描述
我有一个用于 Microsoft Excel 的 VBA 宏。.xls
宏更改文件夹中每个文件的 Headerimage 和 Footercontent 。唯一的问题是页面方向自动设置为横向。我想保持原点的页面方向。这个怎么做?
这是我的宏:
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Dim ImagePath As String
Dim Validation As String
ImagePath = "\logo.jpg"
companyname = "companyname"
contractnumber = "23-23"
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xls*"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
On Error Resume Next
Validation = Dir(ImagePath)
On Error GoTo 0
If Validation = "" Then
MsgBox "Pfad zu Logo falsch: " & ImagePath
Exit Sub
End If
For Each sheet In ActiveWorkbook.Worksheets
sheet.activate
sheet.PageSetup.LeftHeader = "&G"
sheet.PageSetup.LeftHeaderPicture.Filename = ImagePath
sheet.PageSetup.LeftFooter = "&[Datei] © " + companyname + ", Vertragsnummer: " + contractnumber
sheet.DisplayPageBreaks = False
Next sheet
wb.Close SaveChanges:=True
DoEvents
myFile = Dir
Loop
'Message Box
MsgBox "Done"
ResetSettings:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
解决方案
看来您可以先获取工作表的方向值,然后再将其设置为方向。
Sub test()
Dim Ws As Worksheet
Dim i As Integer
Set Ws = ActiveSheet
With Ws.PageSetup
i = .Orientation
.Orientation = i
End With
MsgBox i
End Sub
推荐阅读
- f# - 是否可以在 F# 中定义公共静态只读字段?
- c# - 使用箭头键移动二维数组中的元素并限制移动
- python - 我想知道为什么我制作的图像播放器不能在大尺寸窗口(> 8K 窗口)下正常工作
- apache-kafka - Confluent local start 给出 config.json: No such file or directory
- prolog - Prolog 错误:无权修改静态过程“marital_status/2”
- c# - 发布到 ASP.NET Core 3.1 Web 应用程序时,“[FromBody]MyClass 数据”通常为空
- python - 如何检查任何数组值的长度是否等于 1
- sql - 从当前日期前六个月提取数据不起作用
- php - Laravel根据子数组中元素的数量对数组进行排序
- node.js - doc.save() 不是函数