Results 1 to 11 of 11

Change activate workbook to be vba created workbook

Threaded View

  1. #1
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Change activate workbook to be vba created workbook

    Hey folks

    Got stuck in this one and hope someone can help me out.

    I create a workbook by vba and my problem is simply that I cannot change the new workbook to be the activeworkbook where i can select cells and so fourth. I can insert values in cells in the new workbook, but as I need to copy cells from the original workbook to the new one and further manipulate the data, I need to be able to select cells in the new wb. Thanks in advance for your help! Code is following:

    Sub Test_Excel()
     Dim MyXL As Object 'Excel Application Object
     Dim XL_File As String
     Dim SheetName As String
     Dim curWorkbook As Workbook
     
     Set curWorkbook = ActiveWorkbook
     
     SheetName = "New Sheet Name"
     
    'Create the Excel Application Object.
     Set MyXL = CreateObject("Excel.Application")
     
    'Create new Excel Workbook
     MyXL.Workbooks.Add
     
    MyXL.Worksheets(1).Name = SheetName
     
    MyXL.Application.Visible = True
    
    MyXL.Worksheets(SheetName).Range("A1").Value = "This is a test!!!!"
    ActiveWorkbook.Worksheets(1).Range("b1").Select  'this line and the one below is just to test which is the active workbook..
    MsgBox ActiveWorkbook.Name
    
    Set MyXL = Nothing
    End Sub
    Attached Files Attached Files

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