Closed Thread
Results 1 to 3 of 3

Two Different VBA code to combine in single one.

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2016
    Location
    Nepal, Ktm
    MS-Off Ver
    Microsoft Office 7
    Posts
    9

    Talking Two Different VBA code to combine in single one.

    I am totaly new to VBA world and right now I'm completely lost in those below code where i want to combine them both and make able to run on single userform.


    
    
    Option Explicit
     'API function to enable/disable the Excel Window
    Private Declare Function FindWindowA Lib "user32" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
    Private Declare Function EnableWindow Lib "user32" _
    (ByVal hWnd As Long, ByVal bEnable As Long) As Long
     
    Private Declare Function SetWindowPos Lib "user32" ( _
    ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
    ByVal cy As Long, ByVal wFlags As Long) As Long
     
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOMOVE = &H2
    Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private mlHWnd As Long
    Private mbDragDrop As Boolean
    Private FormHWnd As Long
     
    Private Sub cmdNotTop_Click()
        SetWindowPos FormHWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
    End Sub
     
    Private Sub cmdTop_Click()
        SetWindowPos FormHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
    End Sub
     
    Private Sub UserForm_Activate()
        On Error Resume Next
         'Find the Excel main window
        mlHWnd = FindWindowA("XLMAIN", Application.Caption)
        FormHWnd = FindWindowA(vbNullString, Me.Caption)
        Call cmdTop_Click
         'Enable the Window - makes the userform modeless
        EnableWindow mlHWnd, 1
        mbDragDrop = Application.CellDragAndDrop
        Application.CellDragAndDrop = False
        
        
        
        
        
    End Sub
     
    Private Sub btnOK_Click()
        Application.CellDragAndDrop = mbDragDrop
        Call cmdNotTop_Click
        Unload Me
    End Sub



    and


    
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowLongA Lib "user32" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLongA Lib "user32" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    '
    Private Sub UserForm_Activate()
    Dim hWnd As Long, exLong As Long
    If Application.Version < 9 Then
    hWnd = FindWindow("ThunderXFrame", Me.Caption)
    Else
    hWnd = FindWindow("ThunderDFrame", Me.Caption)
    End If
    exLong = GetWindowLongA(hWnd, -16)
    If (exLong And &H30000) = 0 Then
    SetWindowLongA hWnd, -16, exLong Or &H20000
    Me.Hide: Me.Show
    End If
    End Sub



    One works well for "Always on top feature" and other one for "Famous minimize button" when run separately, Is there any way, I could combine both of there two in a single code and hence i'll have both minimize button and always on top feature on same userform.

    Any Help will be well Appreciated. Thanks in advance.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,122

    Re: Two Different VBA code to combine in single one.

    Duplicate thread: http://www.excelforum.com/excel-gene...ingle-one.html

    Please don't waste everyone's time by posting the same question twice or more times. One is enough.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Two Different VBA code to combine in single one.

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.

    http://www.excelforum.com/excel-gene...ingle-one.html
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need Assistance to Combine Two Code into Single One
    By Naya_Soch in forum Excel General
    Replies: 3
    Last Post: 09-22-2016, 09:08 AM
  2. Combine VBA into a single one
    By JJ77 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2016, 02:11 PM
  3. [SOLVED] Combine values from two or more into a single row.
    By Kimston in forum Excel General
    Replies: 18
    Last Post: 03-01-2015, 07:21 PM
  4. Combine MANY tabs (with single column) into SINGLE tab.
    By nick1000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2013, 02:31 PM
  5. Excel 2007 : Combine multiple columns into a single one
    By daitrangle2308 in forum Excel General
    Replies: 0
    Last Post: 04-19-2012, 06:49 AM
  6. Replies: 6
    Last Post: 08-31-2011, 10:00 AM
  7. combine the two into a single formula please
    By Steved in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-07-2005, 09:05 PM

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