Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() How to use VBA to copy this code from one opened workbook to all opened workbooks ? I need this code under "Thisworkbook" object of each opened workbook. Thank you! Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Application.SendKeys "{F9}" End Sub -- Amolin ------------------------------------------------------------------------ Amolin's Profile: http://www.excelforum.com/member.php...fo&userid=8321 View this thread: http://www.excelforum.com/showthread...hreadid=375868 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This seems to work:
Sub InsertCode() Dim wb As Workbook Dim code As String, checkline As String Dim Ln As Long checkline = "Workbook_SheetSelectionChange" code = "Private Sub Workbook_SheetSelectionChange" & _ "(ByVal Sh As Object, ByVal Target As Range)" & vbCr & _ "Application.SendKeys ""{F9}""" & vbCr & _ "End Sub" On Error Resume Next 'In case project is protected For Each wb In Workbooks With wb.VBProject.VBComponents("ThisWorkbook").CodeModu le Ln = .CountOfLines 'Don't add code if already exists If Not .Find(checkline, 1, 1, Ln, 1) Then _ ..InsertLines Ln + 1, code End With Next On Error GoTo 0 End Sub Regards, Greg "Amolin" wrote: How to use VBA to copy this code from one opened workbook to all opened workbooks ? I need this code under "Thisworkbook" object of each opened workbook. Thank you! Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Application.SendKeys "{F9}" End Sub -- Amolin ------------------------------------------------------------------------ Amolin's Profile: http://www.excelforum.com/member.php...fo&userid=8321 View this thread: http://www.excelforum.com/showthread...hreadid=375868 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thank you for your code! But there is a error says: "Application define error or Object define error" "With wb.VBProject.VBComponents("ThisWorkbook").CodeModu le" could you give a help? -- Amolin ------------------------------------------------------------------------ Amolin's Profile: http://www.excelforum.com/member.php...fo&userid=8321 View this thread: http://www.excelforum.com/showthread...hreadid=375868 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Greg Wilson shared this with us in microsoft.public.excel.programming:
This seems to work: *snip* code containing VBComponents.CodeModule.InsertLines And if you have a McAfee virusscanner, it will cheerfully erase any code module that contains .InsertLines. -- Amedee Van Gasse using XanaNews 1.17.4.1 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thank you, I have Symantec Anti _Virus installed -- Amoli ----------------------------------------------------------------------- Amolin's Profile: http://www.excelforum.com/member.php...nfo&userid=832 View this thread: http://www.excelforum.com/showthread.php?threadid=37586 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Amolin shared this with us in microsoft.public.excel.programming:
Thank you, I have Symantec Anti _Virus installed. Which is no guarantee. I experienced the problem with McAfee, but other AV may do the same. Perhaps not now but who knows about future versions? The problem is with .InsertLines (and also with .DeleteLines). Some macro viruses use this to add their own code to other workbooks. So a proactive AV may not know the virus yet, but it sees the .InsertLines activity and it say, better safe than sorry. If you have a standalone AV, you can perhaps disable this particular scanning feature. With a managed or network scanner: don't know, perhaps not. In My Humble Opinion it is important that not only you know there can be a problem, but also WHY there can be a problem. That way you can work around it. -- Amedee Van Gasse using XanaNews 1.17.4.1 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
problem with Linking workbooks via "copy" and "paste link" | Excel Discussion (Misc queries) | |||
Copying "ThisWorkbook" objects | Excel Programming | |||
Copying "ThisWorkbook" objects | Excel Programming | |||
Can you "duplicate" "copy" listboxes and code to multiple cells? | Excel Programming |