+ Reply to Thread
Results 1 to 8 of 8

Working with Application in VBA

  1. #1
    Registered User
    Join Date
    09-29-2014
    Location
    TIjuana, Mexico
    MS-Off Ver
    MSO 2010, MSO 2013
    Posts
    53

    Working with Application in VBA

    Hi guys, any help or new way to do the trick will be welcome


    I have a userform that when initialized, it goes to an excel workbook and gets data from a sheet to populate a combobox. No big deal.
    When the button is clicked, I want, in that same workbook, different sheet, to add the data that was typed in the userform.

    Code for Sub Initialize is:

    Please Login or Register  to view this content.

    My troubles start in the Click Event, do I need to close the application when the Initialize event ends, or leave it idle and call it back in the Click Event? If so, how can I do that?

    I have this...

    Please Login or Register  to view this content.

    Help!

    Thanks in advance.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Working with Application in VBA

    Out of curiosity, which application are you running the code from?

    You could add the data to the other sheet while you are in the UserForm Initialize event. Just add code similar to that you have shown in your second macro that will add the data to the second worksheet. this portion of the code is what I am referring to. No need to go back an re-invent the wheel when you have the data right there.

    Please Login or Register  to view this content.
    With a little editing, you could probably use the same source reference you use to load the combo box data and label data in the same loop.
    Last edited by JLGWhiz; 02-28-2018 at 05:11 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    09-29-2014
    Location
    TIjuana, Mexico
    MS-Off Ver
    MSO 2010, MSO 2013
    Posts
    53

    Re: Working with Application in VBA

    Hey, thanks.

    Unfortunately, I can't do that, as the userform initializes with only those 2 values and the rest (not shown) must be typed in.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Working with Application in VBA

    Quote Originally Posted by MarBoTJ View Post
    Hey, thanks.

    Unfortunately, I can't do that, as the userform initializes with only those 2 values and the rest (not shown) must be typed in.
    OK, I missed the typed in part in the OP. You did not answer my question about the host file for the code, but based on the fact that your controls may not have complete data at the time you initialize the UserForm, then you would have to have a separate macro to access the data and do the copy/paste. Assuming you are in Access, Power Point, Word or some other MS appliction other than Excel as the host file, you would also need to use the CreateObject methop to get the Excell Application and activate the workbook (your first code does not close the workbook nor quit the Excel Application, so you should be able to just create the Object and use it to activate the workbook and do your stuff. Been a while since I worked across applications so I could be wrong, but it seems logical that it would work.

  5. #5
    Registered User
    Join Date
    09-29-2014
    Location
    TIjuana, Mexico
    MS-Off Ver
    MSO 2010, MSO 2013
    Posts
    53

    Re: Working with Application in VBA

    Sorry about that,
    I'm purely working with Excel. I'm testing some code I'm making by myself, maybe there is already something on the web but I decided to put my mind to work for a while.
    I'll let you know how this ends.

    Thanks anyways.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Working with Application in VBA

    If you are working only with Excel, then you do not need the CreateObject method to access the application. You are already in the application when you open the first workbook. So you are creating a lot of code that is unnecessary in the procedures in the OP. All you need are the Workbook and Sheet references to get to where you want to access in the files. Understanding the Excel object model is crucial to writing good code.

  7. #7
    Registered User
    Join Date
    09-29-2014
    Location
    TIjuana, Mexico
    MS-Off Ver
    MSO 2010, MSO 2013
    Posts
    53

    Re: Working with Application in VBA

    Yeah, I realized that yesterday, I'm still understanding the application object to know how to manipulate it. I guess that'll do the trick.
    I'll close this post, if something else comes up I'll post a new question.

    Thanks.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Working with Application in VBA

    Quote Originally Posted by MarBoTJ View Post
    Yeah, I realized that yesterday, I'm still understanding the application object to know how to manipulate it. I guess that'll do the trick.
    I'll close this post, if something else comes up I'll post a new question.

    Thanks.
    You're welcome,
    regards, JLG

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Application.CalculateBeforeSave not working.
    By radddogg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-01-2017, 08:30 AM
  2. [SOLVED] Application.vlookup not working
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-17-2016, 09:10 AM
  3. Application Run not working
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2016, 02:53 AM
  4. Application.OnTime Not Working for me
    By treymass in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2013, 02:07 PM
  5. Application.ScreenUpdating not working with Application.Run
    By WaqasTariq in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2012, 02:24 PM
  6. Application.Wait not working
    By Herbie1809 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2010, 07:11 PM
  7. Application.Run not working
    By Lokutus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2006, 04:25 PM

Tags for this Thread

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