+ Reply to Thread
Results 1 to 10 of 10

Retrieve Data without opening excel file

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Retrieve Data without opening excel file

    Please find attached 2 excel sheet for referance.
    There is a Command Button in "GetExcel_Data_without_Opening" excel file attached
    with VBA code.
    Pressing the command button retreives the value from "Book_sendData1" Sheet and shows in Message box.
    Instead of showing in the message box, I want to paste this value in Cell B15 of "GetExcel_Data_without_Opening" excel sheet...

    Please edit the VB Code to achive this....

    Please let me know if you have any questions

    Thank you,

    Riz Momin
    Attached Files Attached Files
    Last edited by rizmomin; 02-13-2010 at 03:27 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Retrive Data without opening excel file

    Hello Riz,

    It has been awhile. Hope things are going well for you and your family. Here is the updated macro.
    Private Sub CommandButton1_Click()
    
        Dim ClosedWkb As Variant
        Dim xl As New Excel.Application
        Dim xlw1 As Excel.Workbook
        
        
        ' Open the excel file.
        ' replace the "c:\myDir\book1.xls" below with your excel file name.
        ClosedWkb = ThisWorkbook.Path & "\" & "Book_SendData1.xls"
        Set xlw1 = xl.Workbooks.Open(ClosedWkb)
        
        ' replace "Sheet1" with the sheet that you want to get the data from it.
        ' Get the value from cell(2,3) of the sheet.
        ThisWorkbook.Worksheets("Sheet1").Range("B15") = xlw1.Sheets("Sheet1").Cells(2, 3)
        
        ' Close worksheet without save changes.
        ' If you want to save changes, replace the False below with True
        xlw1.Close False
        
        ' free memory
        Set xlw1 = Nothing
        Set xl = Nothing
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Retrive Data without opening excel file

    Leith : It has been long time.

    Thank you so much....this works great...
    Is it possibel to use this code if Excel file is password protected...i mean can you by pass password..


    Thank you so much

    Riz Momin

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Retrive Data without opening excel file

    You can't bypass it, but you can apply it:

    Set xlw1 = xl.Workbooks.Open(FileName:=ClosedWkb, Password:="secret")
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    06-09-2011
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Retrive Data without opening excel file

    Hey Leith,
    Can you please help me with your code so that it can get name of the file from ComboBox1 also I want to select the data range A1:G100" to be copied in the closed workbook.

    Regards,

    Vikas.

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Retrive Data without opening excel file

    Thank u so much ...this works great...
    Need to know what chances would i need to make if i need to copy Range of data instaed of 1 cell

    Riz Momin

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Retrive Data without opening excel file

    Hello Riz,

    This macro has been changed to copy over only the values of the range "C2:F3" on "Sheet1" of the source workbook. You can change this the sheet name and range to what you are using. I also added in the lines for password protection.
    Private Sub CommandButton1_Click()
    
        Dim ClosedWkb As Variant
        Dim ColsCnt As Long
        Dim RowsCnt As Long
        Dim SrcRng As Range
        Dim xl As New Excel.Application
        Dim xlw1 As Excel.Workbook
        
        
        ' Open the excel file.
        ' replace the "c:\myDir\book1.xls" below with your excel file name.
        ClosedWkb = ThisWorkbook.Path & "\" & "Book_SendData1.xls"
        Set xlw1 = xl.Workbooks.Open(ClosedWkb)
        x1w1.Unprotect "password"
        
        ' Set the Source Range to "C2:F3"
        Set SrcRng = xlw1.Sheets("Sheet1").Range("C2:F3")
        
        ' Paste the Source Range in this workbook starating with cell "B15"
        ColsCnt = SrcRng.Columns.Count
        RowsCnt = SrcRng.Rows.Count
        ThisWorkbook.Worksheets("Sheet1").Range("B15").Resize(RowsCnt, ColsCnt) = SrcRng.Value
        
        
        ' Close worksheet without save changes.
        ' If you want to save changes, replace the False below with True
        x1w1.Protect "password"
        xlw1.Close False
        
        ' free memory
        Set xlw1 = Nothing
        Set xl = Nothing
    
    End Sub

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Retrive Data without opening excel file

    Thank U so much this works great for me....
    Will let you know if i need any futher modification...
    Hey can you please let me know how to add [SOLVED] tag..

    Riz Momin
    Last edited by rizmomin; 02-14-2010 at 03:47 PM.

  9. #9
    Registered User
    Join Date
    12-16-2011
    Location
    dubai
    MS-Off Ver
    Excel 2007
    Posts
    1

    need help....

    sir, actually i am facing problem in excel while taking/linking the value from one file to another file.
    i got 2 file - 1st one is master where it shows total stock
    2nd file - where i add & remove item. so final difference qty in 2nd file should appear in 1st file.

    the problem is if i open 1st file without opening 2nd file it shows error as " #value! ", it's not showing any value in 2nd file.

    how to solve this problem.

    please reply to this query asap...plz...........

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Retrieve Data without opening excel file

    Hey Vikas,

    Welcome to the Forum.

    I understand that you need help similar to this thread. However, as per the forum rules, you cannot post your thread in the thread of another user. Hence, please re-open a new thread. You can put the link to this thread so that the person answering your question can get a lead.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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