在自动化不起作用的情况下,拥有和更新150张幻灯片的管理层很难。在Windows上,您可以轻松更新Excel中的数字和连接图(链接到源数据)更改。
我不知道是否有人想知道,但这似乎是一个众所周知的问题:
要在图片上绘画,要清楚我想要用我的编码实现什么,这里是故事的其余部分:在我们的公司,有各种各样的系统在一起。我正在使用Mac(和Office Mac),而其他人请求相同的数据并使用Office Windows。正如我发现它的Apple系统的安排,它禁用了MSO程序或自动化的许多功能。我在Windows和Mac上使用Office测试了这个自动更新故事并执行了以下步骤:
所以这只是对更大问题的描述。为了解决这个问题(可能只在几年内修复......已经是一个众所周知的问题)我试图使用VBA。
在Windows和Mac之间区分我的代码,最后应该有一个代码供所有用户使用。到目前为止我做了什么:
- >这里我有问题,因为Mac上保存的文件是空的(0字节)。
注意:我的例子excel很容易,包含3张:UKI,France和Pictures。 UKI和France是带有数字和图形的示例表,由这些表创建。图表'范围被复制并用于逐个复制到图片中。目的是复制图表,保存 - 并为每个国家/地区(例如UKI France)重复此图表。
我正在努力的是出口部分。在Mac上文件通常保存在一个特殊的microsoft文件夹中.... / users /.../ microsoft.com/data /......
当我尝试添加"特殊文件夹&#34 ;;如桌面,图片,文档(等)我收到一条错误消息,说“&34;许可被拒绝"”。这里的Apple Sandbox要求似乎阻止了我。 只有特殊文件夹"图片"似乎工作:保存的文件出现,但就像在microsoft文件夹中一样,它们被创建为空。
我是VBA的新手,所以这可能是一堆乱七八糟的代码 - 但是为什么保存的jpg / jpeg。文件为空(其他图片格式为空)??
到目前为止,我的编码:(可能有点不合适)
Sub TakePictures()
'check for running system; then play script for Mac or Windows
#If Mac Then
'I am a Mac
MsgBox "Call your Mac_Macro"
MsgBox "Call your Mac_Macro"
Dim i As Integer
Dim intCount As Integer
Dim objPic As Shape
Dim objChart As Chart
'UKI
'copy the range as an image
Call Worksheets("UKI").Range("D1:I14").CopyPicture(xlScreen, xlPicture)
'remove all previous shapes in sheet2
intCount = Worksheets("Picture").Shapes.Count
For i = 1 To intCount
Worksheets("Picture").Shapes.Item(1).Delete
Next i
'create an empty chart in sheet2
Worksheets("Picture").Shapes.AddChart
'activate sheet2
Worksheets("Picture").Activate
'select the shape in sheet2
Worksheets("Picture").Shapes.Item(1).Select
Set objChart = ActiveChart
'paste the range into the chart
Worksheets("Picture").Shapes.Item(1).Line.Visible = msoFalse
Worksheets("Picture").Shapes.Item(1).Width = Range("D1:I14").Width
Worksheets("Picture").Shapes.Item(1).Height = Range("D1:I14").Height
objChart.Paste
' Call AppleScript to get a special folder
Dim NameFolder As String
Dim SpecialFolder As String
' You can use : home, documents, desktop, music, pictures, movies, applications
NameFolder = "documents"
If Int(Val(Application.Version)) > 14 Then
SpecialFolder = _
MacScript("return POSIX path of (path to " & NameFolder & " folder) as string")
'Replace line needed for the special folders Home and documents
SpecialFolder = _
Replace(SpecialFolder, "/Library/Containers/com.microsoft.Excel/Data", "")
Else
SpecialFolder = MacScript("return (path to " & NameFolder & " folder) as string")
End If
Dim fileAccessGranted As Boolean
Dim filePermissionCandidates
'Create an array with file paths for which permissions are needed_
'filePermissionCandidates = Array("/Users/<user>/Desktop/test1.txt", "/Users/<user>/Desktop. /test2.txt")
'Request Access from User_
'fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
'save the chart as a JPEG
Dim LoginName As String
LoginName = UCase(GetUserID)
'ChDir "C:\Users\" & LoginName & "\Specialfolder"\"
Debug.Print LoginName
'objChart.Export ("C:Users\" & LoginName & "\documents\FY1718_UKI.jpg")
objChart.Export ("/Users/fabianvoss/pictures/FY1718_UKI.pdf")
'*here the export does give me empty files - tested out already all different kind of different data types.
#Else
'I am Windows
MsgBox "Call Windows_Macro"
'Activeselection.Export Filename:="D:\FY1718_UKI.jpg", Filtername:="JPG"
'Existiert Bild-Ordner unter Laufwerk C? -> Abfrage mit if:
'Wenn ja: Weiter
'Sonst: erstellen, dann weiter
On Error Resume Next
MkDir "C:\VBATestBilder"
On Error GoTo 0
'Neues Sheet erstellen: "Picture"
Dim i As Integer
Dim intCount As Integer
Dim objPic As Shape
Dim objChart As Chart
'UKI
'copy the range as an image
Call Worksheets("UKI").Range("D1:I14").CopyPicture(xlScreen, xlPicture)
'remove all previous shapes in sheet2
intCount = Worksheets("Picture").Shapes.Count
For i = 1 To intCount
Worksheets("Picture").Shapes.Item(1).Delete
Next i
'create an empty chart in sheet2
Worksheets("Picture").Shapes.AddChart
'activate sheet2
Worksheets("Picture").Activate
'select the shape in sheet2
Worksheets("Picture").Shapes.Item(1).Select
Set objChart = ActiveChart
'paste the range into the chart
Worksheets("Picture").Shapes.Item(1).Line.Visible = msoFalse
Worksheets("Picture").Shapes.Item(1).Width = Range("D1:I14").Width
Worksheets("Picture").Shapes.Item(1).Height = Range("D1:I14").Height
objChart.Paste
'save the chart as a JPEG
objChart.Export ("C:\VBATestBilder\FY1718_UKI.Jpeg")
'FRANCE
'copy the range as an image
Call Worksheets("France").Range("D1:I14").CopyPicture(xlScreen, xlPicture)
'remove all previous shapes in sheet2
intCount = Worksheets("Picture").Shapes.Count
For i = 1 To intCount
Worksheets("Picture").Shapes.Item(1).Delete
Next i
'create an empty chart in sheet2
Worksheets("Picture").Shapes.AddChart
'activate sheet2
Worksheets("Picture").Activate
'select the shape in sheet2
Worksheets("Picture").Shapes.Item(1).Select
Set objChart = ActiveChart
'paste the range into the chart
Worksheets("Picture").Shapes.Item(1).Line.Visible = msoFalse
Worksheets("Picture").Shapes.Item(1).Width = Range("D1:I14").Width
Worksheets("Picture").Shapes.Item(1).Height = Range("D1:I14").Height
objChart.Paste
'save the chart as a JPEG
objChart.Export ("C:\VBATestBilder\FY1718_France.Jpeg")
'Delete new chart
#End If
End Sub
我不明白为什么Mac上的文件是空的......?
(然后,如果文件可以保存,我需要将它们导入Powerpoint到不同幻灯片上的不同位置(在Windows上它很容易,在Mac上可能很难))
感谢您的阅读, 我将不胜感激任何帮助
PS:我对VBA来说是全新的
的问候, 费边