vba 在vba中粘贴链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10003968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Paste link in vba
提问by Steveng
I want to paste link from one sheet to another
我想将链接从一张纸粘贴到另一张纸上
Range("A1:D1").Select
Range("D1").Activate
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste Link:=True
However, the code would make the sheet to switch to Sheet2 from Sheet1. Is there anyway that I could paste the link without switching the sheet?
但是,代码会使工作表从 Sheet1 切换到 Sheet2。无论如何,我可以在不切换工作表的情况下粘贴链接吗?
Thanks.
谢谢。
回答by Tahbaza
This will work:
这将起作用:
ThisWorkbook.Worksheets("Sheet2").Range("D1").Formula = "=Sheet1!D1"
回答by Siddharth Rout
I guess this is what you are trying?
我想这就是你正在尝试的?
Sub Sample()
Dim i As Long
For i = 1 To 4
Sheets("Sheet2").Cells(1, i).Formula = "=Sheet1!" & _
Split(Cells(, i).Address, "$")(1) & "1"
Next i
End Sub
回答by chris neilsen
This code will do the same as your code snippet without changing the active sheet.
此代码将与您的代码片段执行相同的操作,而无需更改活动工作表。
Range("A1:D1").Copy
Worksheets("Sheet2").Paste Link:=True
Note that this (and your code) will copy from the active sheet. If you want to copy from a sheet other than the active sheet, use somthing like
请注意,此(和您的代码)将从活动工作表中复制。如果要从活动工作表以外的工作表复制,请使用类似
Worksheets("Sheet1").Range("A1:D1").Copy
Worksheets("Sheet2").Paste Link:=True
回答by Victor Braga
I've had the same problem just now. I just realized then that TightVNC was connected to another machine when I tried to run my code. When I closed it, the code run as usual.
我刚才遇到了同样的问题。当我尝试运行我的代码时,我才意识到 TightVNC 已连接到另一台机器。当我关闭它时,代码照常运行。
Possibly this happens because some software might be taking control of your clipboard. Just close anything you don't need, like VNCs or Virtual Machines.
可能发生这种情况是因为某些软件可能正在控制您的剪贴板。只需关闭不需要的任何东西,例如 VNC 或虚拟机。
回答by Hotwire20
You could use Application.ScreenUpdating = False
and then return it to true after the paste has completed.
您可以使用Application.ScreenUpdating = False
,然后在粘贴完成后将其返回为 true。
Example:
例子:
Application.ScreenUpdating = False
Worksheets("Sheet1").Range("D1").Copy
Worksheets("Sheet2").Activate
Range("Range You Want To Paste").Select
ActiveSheet.PasteSpecial Link:=True
Worksheets("Sheet1").Activate
Range("A Range You Want Active").Activate
Application.ScreenUpdating =true
回答by Jerry Beaucaire
Your LINK desire cannot be done without selecting the sheet. But you can make the fact that it does that invisible to the eye.
不选择表格就无法实现您的 LINK 愿望。但是你可以让眼睛看不见它。
Option Explicit
Sub test()
Application.ScreenUpdating = False
Sheets("Sheet1").Range("A1:D1").Copy
With Sheets("Sheet2")
.Activate
.Range("A1").Select
ActiveSheet.Paste Link:=True
End With
Sheets("Sheet1").Activate
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub