ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
123
返回列表 发新帖
楼主: hempy2100

[求助] vba 复制电脑文件到系统剪切板

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-25 15:36 | 显示全部楼层
芐雨 发表于 2019-12-25 14:32
两边加单引号啊
FileList = "'" & ActiveDocument.Path & "\" & "2020BC_Hall " & Application.Acti ...

不知为何,您给我的代码可以,但又回到了之前的问题,可以在电脑的桌面或电脑本地的其它文件夹里粘贴,就是不能在微信或QQ里粘贴,绝望

我把全部代码都发上来了,由于用的visio 不是excel,所以没有上附件。


Sub 存为PDF()

Dim lshg As String
Dim DiagramServices As Integer
    Dim pscode As String

Dim oShellApp, oShellAppWindows, oWin, oWind, Ste, Str, Sty

    Ste = ActiveDocument.Path
    Str = Left(Ste, Len(Ste) - 1)
    Sty = Right(Str, Len(Str) - InStrRev(Str, "\"))

    Set oShellApp = CreateObject("Shell.Application")
    Set oShellAppWindows = oShellApp.Windows
    For Each oWin In oShellAppWindows
    For Each oWind In oShellAppWindows
        If InStr(1, oWind.locationname, Sty, vbTextCompare) > 0 Then oWind.Quit
    Next
        If InStr(1, oWin.locationname, Sty, vbTextCompare) > 0 Then oWin.Quit
    Next
    Set oWin = Nothing
    Set oShellApp = Nothing
    Set oShellAppWindows = Nothing
   
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("填充颜色")
    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(RGB(255,255,0))"
    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEME(""FillColor""),THEME(""FillColor2""))))"
    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaU = "1"

    lshg = InputBox("PDF│请输入企业简称:")
   
If Application.ActivePage.Name = "Hall 8.2" Then
    Application.ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, ActiveDocument.Path & "\" & "2020秋季焙烤展_" & Application.ActivePage.Name & " " & lshg & ".pdf", visDocExIntentPrint, visPrintCurrentPage, 3, 3, False, True, True, True, False
Else
    Application.ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, ActiveDocument.Path & "\" & "2020BC_Hall " & Application.ActivePage.Name & " " & lshg & ".pdf", visDocExIntentPrint, visPrintCurrentPage, 3, 3, False, True, True, True, False
End If

    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(MSOTINT(RGB(255,255,255),-25))"
    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEME(""FillColor""),THEME(""FillColor2""))))"
    On Error Resume Next
    Application.ActiveWindow.Page.Shapes.ItemFromID(ActiveWindow.Selection(1).ID).CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaU = "1"
   
    Application.EndUndoScope UndoScopeID1, True

    pscode = "powershell  $filelist =" & "'" & ActiveDocument.Path & "\" & "2020BC_Hall " & Application.ActivePage.Name & " " & lshg & ".pdf'" & vbCrLf & "$col = New-Object Collections.Specialized.StringCollection " & vbCrLf & "foreach($file in $filelist){$col.add($file)}" & vbCrLf & "Add-Type -AssemblyName System.Windows.Forms" & vbCrLf & "[Windows.Forms.Clipboard]::setfiledroplist($col)"
    Shell pscode, vbHide


ActiveDocument.DiagramServicesEnabled = DiagramServices
Shell "Explorer.exe " & ActiveDocument.Path, vbNormalFocus


End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-25 15:49 | 显示全部楼层
芐雨 发表于 2019-12-25 14:32
两边加单引号啊
FileList = "'" & ActiveDocument.Path & "\" & "2020BC_Hall " & Application.Acti ...

另外,我在用API里的cutorcopyfiles时,代码为CutOrCopyFiles ActiveDocument.Path & "\" & Application.ActiveDocument.Name时(代码里没有&".docx"),是可以在本地粘贴,也可以在微信里粘贴。

请问跟这个问题有关系吗?

Sub 更新()
   
Selection.WholeStory
Selection.Fields.Locked = False
Selection.Fields.Update
Selection.Fields.Locked = True
If MsgBox("关闭程序并复制文件?", vbOKCancel, "提示") = vbOK Then
ActiveDocument.Save
CutOrCopyFiles ActiveDocument.Path & "\" & Application.ActiveDocument.Name
Shell "Explorer.exe " & ActiveDocument.Path, vbNormalFocus
ActiveDocument.Close
Word.Application.Quit
End If
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-1-18 15:46 | 显示全部楼层
芐雨 发表于 2019-12-25 14:32
两边加单引号啊
FileList = "'" & ActiveDocument.Path & "\" & "2020BC_Hall " & Application.Acti ...

大神,再追问一下,地址里是否可以用通配符呢

TA的精华主题

TA的得分主题

发表于 2020-1-18 17:43 | 显示全部楼层
hempy2100 发表于 2019-12-23 13:05
我在国外网站查到以下代码,可是还是不懂

Option Explicit

在国外的哪个网站看到的,分享一下那网站

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-1-18 22:40 | 显示全部楼层
FOB_FN_L 发表于 2020-1-18 17:43
在国外的哪个网站看到的,分享一下那网站

为自己的问题在网上随便搜索的看到的,搜索英文网页,已经忘记了

TA的精华主题

TA的得分主题

发表于 2023-1-1 14:11 | 显示全部楼层
芐雨 发表于 2019-12-23 18:29
api确实比较长,来个曲线救国吧,用powershell

win7及以上系统自带powersehll,你可以理解为cmd批处理的 ...

感谢!测试可用
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-20 00:44 , Processed in 0.026927 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表