Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA for Mac Word 2016下载文件_Vba_Macos_Ms Word - Fatal编程技术网

使用VBA for Mac Word 2016下载文件

使用VBA for Mac Word 2016下载文件,vba,macos,ms-word,Vba,Macos,Ms Word,我正在尝试为Mac更新Word 2016的模板 在前面的代码中,我能够运行MacScript()命令来运行AppleScript,而AppleScript又运行shell脚本 现在运行这样一个脚本的唯一方法似乎是使用AppleScriptTask,这要求脚本已经存在于Application Scripts文件夹中,这在我试图将它分发给其他(非精明的)用户时会出现问题 我正试图找出其他方法来做这件事,但经过数周的研究,我仍然感到困惑 我运行的脚本可以做各种事情,但现在最重要的是从网站下载模板的更新

我正在尝试为Mac更新Word 2016的模板

在前面的代码中,我能够运行MacScript()命令来运行AppleScript,而AppleScript又运行shell脚本

现在运行这样一个脚本的唯一方法似乎是使用AppleScriptTask,这要求脚本已经存在于Application Scripts文件夹中,这在我试图将它分发给其他(非精明的)用户时会出现问题

我正试图找出其他方法来做这件事,但经过数周的研究,我仍然感到困惑

我运行的脚本可以做各种事情,但现在最重要的是从网站下载模板的更新版本。我在Windows端使用ActiveX来实现这一点,但在Mac上无法实现

是否有人可以建议使用VBA的Mac Word 2016的其他方法(仅最好)

谢谢大家!

试试这个:

ActiveDocument.FollowHyperlink "http://yoursite.com/yourpackage.zip"

下面是我为实现这一点所做的。我设置了一个定时器来等待下载,因为它是在VBA之外完成的

Function Download(Path As String) As String

On Error GoTo Handler
Dim User, UserPath, dlFile, base_dest, final_dest, FName As String
Dim Timer As Boolean
Timer = False
Dim timeout As Variant

timeout = Now + TimeValue("00:00:10")
User = Environ("USER")
UserPath = "/Users/" & User & "/Downloads/"
base_dest = "/Users/" & User & [move/path/]
final_dest = base_dest & FName
ActiveDocument.FollowHyperlink Address:=Path

If Dir(final_dest) <> "" Then
    Kill final_dest
End If

Timer = True
ReTry:
If Dir(dlFile) <> "" Then
    FileCopy dlFile, final_dest
    Kill dlFile
    Download = final_dest
    Exit Function
End If

Handler:
If Err.Number = 53 And Timer = False Then
    Resume Next
 ElseIf Err.Number = 53 And Timer = True Then
    If Now > timeout Then
        MsgBox "There is a problem downloading the file. Please check your internet connection."
        End
    Else
        Resume ReTry
    End If
Else
    MsgBox Err.Number & vbNewLine & Err.Description
    End
End If
End Function
函数下载(路径为字符串)为字符串
关于错误转到处理程序
Dim User、UserPath、dlFile、base_dest、final_dest、FName As String
将计时器设置为布尔值
计时器=错误
变暗超时
超时=现在+时间值(“00:00:10”)
用户=环境(“用户”)
UserPath=“/Users/”&User&“/Downloads/”
base_dest=“/Users/”&User&[move/path/]
最终目的地=基本目的地和名称
ActiveDocument.FollowHyperlink地址:=路径
如果目录(最终目的地)“,则
杀死最后的目标
如果结束
定时器=真
重试:
如果Dir(dlFile)“,则
文件副本dlFile,最终目的地
杀死dlFile
下载=最终目的地
退出功能
如果结束
处理程序:
如果Err.Number=53,Timer=False,则
下一步继续
ElseIf Err.Number=53,Timer=True,则
如果现在>超时,则
MsgBox“下载文件时出现问题。请检查您的internet连接。”
终点
其他的
恢复重试
如果结束
其他的
MsgBox错误编号、vbNewLine和错误说明
终点
如果结束
端函数

这在下载文件方面起作用。但它似乎无法让我控制文件的下载位置,也无法告诉我下载位置,尽管我还没有深入了解,但似乎试图找到浏览器的默认保存位置会导致更多的复杂情况。它默认为用户目录中的downloads文件夹。是的。我只是在想,如果有人更改了默认的下载文件夹,我将找不到它。它工作得很好。我将其下载到默认下载文件夹,然后将其移动到需要的位置(使用VBA)。