+ Reply to Thread
Results 1 to 5 of 5

Event when Excel window is activated

Hybrid View

  1. #1
    Registered User
    Join Date
    06-07-2010
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010
    Posts
    44

    Event when Excel window is activated

    I'm trying to copy data from one program to excel. To save time I want excel to do all the pasting for me.

    So, I have one excel workbook open and MS Dynamic NAV open.

    I copy the data from NAV and then when I switch to the excel workbook I want it to paste the data in itself.

    I've written the code to paste the data in. That works fine, however I can't get this code to fire when I activate or switch to the excel window. I've tried the following but it won't work

    Private Sub Workbook_Activate()
        
        Dim pasteBoard As New MSForms.DataObject
        Dim pData As String
        Dim startCell As Range
        Set startCell = Range("D1")
        
        pasteBoard.GetFromClipboard
        pData = pasteBoard.GetText
        
        Do
            Set startCell = startCell.Offset(1, 0)
        Loop Until IsEmpty(startCell)
    
        startCell.Value = pData
    
    End Sub
    And the following as well,

    Private Sub Workbook_WindowActivate(ByVal Wn As Window)
    
        ' 'SAME CODE' '
    
    End Sub
    Any thoughts?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: Event when Excel window is activated

    There is no event for that, I'm afraid. Excel's events only relate to things that happen within the application.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Event when Excel window is activated

    maybe the rezize event
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    06-07-2010
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: Event when Excel window is activated

    But am I not activating the application or workbook or something like that....

    Private Sub App_WorkbookActivate(ByVal Wb As Workbook)
    Would this work? Don't really know where to put it....

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: Event when Excel window is activated

    No - that will only fire when you switch between workbooks in Excel.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1