+ Reply to Thread
Results 1 to 15 of 15

VBA needed to copy data from an open unsaved attachment to existing workbook

  1. #1
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    VBA needed to copy data from an open unsaved attachment to existing workbook

    Hi all,
    I am a bit of a novice so please make any responses easy to follow if possible.
    I receive a report each day as an attachment. I want to be able to open this attachment without saving it and then have a macro in my existing workbook to identify this open sheet and copy a range of cells and then paste this into a range of cells in my existing workbook.
    It will always be the same range copied and the same range pasted into.
    I just cannot seem to find a code that will do this. The attachment also has a different name each time so the only way to tell Excel which one it is would be to say it is the only other open spreadsheet other than the existing workbook.
    I am new to this forum so be gentle with me. LOL.
    Any help would be very much appreciated as I am pulling my hair out and I don't have much to spare.

    Thanks in advance

  2. #2
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Bit more Information Required...

    Names of Workbook 1 and Workbook 2 (Example).
    Worksheet to copy from.
    Range to Copy.
    Worksheet to Paste to.
    Range to Paste to.

    Up load an example from both Workbooks.

    Regards

    JRidge

  3. #3
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Hi JRidge

    0the main sheet that is saved and to be copied to is called "Universal BF Tool" and the attachment to be copied from is called "Report...(The end of this name varies each time by date,etc)

    I have the tool set up to take all the entries pasted into it and filter out only those that need to be looked at. This all works fine but as many users will be using this I want to automate the pasting in too to avoid people copying too many columns, not enough columns, etc, overwriting formulae or whatever.
    So I want people to open the attachment and then open the tool, hit a button and have the entries copied and pasted into the sheet and then close the attachment.
    The range on the attachment to be copied will be Sheet 1(A15:K10000) and the range to be pasted into will be Sheet 1(named Input Sheet)(K2:U10000
    I cannot upload examples. Sorry, but hope this info is enough

    I appreciate you taking the time to help me

  4. #4
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Where would these files be..

    Same Folder?

  5. #5
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    As a Start:

    Paste this in a Standard Modul in the Destination Workbook.

    Please Login or Register  to view this content.
    Close VBA.

    Alt+F8 and then click Run.


    Just need to work out how to set the Source Workbook title as Report*wildcard.

    Regards

    JRidge

  6. #6
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Would the Report be the newest file in the folder?

  7. #7
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    No the copy from workbook would be an unsaved open attachment and users would have their own versions of the tool saved in their own folders.
    This is why I was hoping there was a way to just have a code that referenced the only other open workbook on the desktop which would be the open attachment and then copy the relevant cells from it to paste in the workbook containing the macro.
    Is it not possible to reference workbooks unless they are saved somewhere? As this would mean users would need to save the attachments with a specific filename in the same folder as the tool and then create a version for each person referencing the folder they are using. But that would not be very practical and I have seen codes for using unsaved files but could not amend ant of them to make them work for me.

  8. #8
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    But isn't the Report saved somewhere on the System. They must have opened it from somewhere?

  9. #9
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Ok easy....

    Paste this in Module in Destination Workbook:

    Please Login or Register  to view this content.
    The Source Workbook needs to be opened second. First open the Destination Workbook and then the Source Workbook.

  10. #10
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Yes , sorry it would be in their outlook inbox attached to an email called Webmaster....(again tis would change each day. Could we tell Excel to look for an email with the subject Report* received today in the inbox, open the attachment and extract the data?

  11. #11
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    See Post #9

  12. #12
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    OK Will try this and get back to you. Thanks so much

  13. #13
    Registered User
    Join Date
    10-31-2014
    Location
    uk
    MS-Off Ver
    2003
    Posts
    6

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    JRidge
    You are an absolute star.
    That worked beautifully.
    Thank you so much for taking the time to help me with this.
    I really appreciate it.
    Enjoy the rest of your weekend
    Take care

  14. #14
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Perfect.

    If the Solution is what you wanted the please mark this thread as solved. (Top of Thread, under "Thread Tools").

    Also if you think i helped Please don't forget to add reputation using the * in one of my posts..

    Regards

    JRidge

  15. #15
    Forum Contributor
    Join Date
    03-10-2013
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2007
    Posts
    125

    Post Re: VBA needed to copy data from an open unsaved attachment to existing workbook

    Paste this in Module of copiedToWorkbook:


    Public Sub CopyDataFromAnOpenUnsavedAttachmentToExistingWorkbook()
    '******Supposition: In Excel two workbook is opened(copiedToWorkbook, copiedFromWorkbook) and one workbook has one worksheet.******
    Const copiedFromWorkbookName_FirstCharacters As String = "Report"
    Const copiedToRangeName As String = "K2:U10000"
    Const copiedFromRangeName As String = "A15:K10000"
    Dim copiedTo, copiedFrom As Range
    Dim copiedToWorkbook, copiedFromWorkbook As Object
    Set copiedToWorkbook = ActiveWorkbook

    For Each openedWorkbook In Workbooks
    'MsgBox openedWorkbook.Name
    Select Case openedWorkbook.Name
    Case copiedToWorkbook.Name
    Case Else
    If Mid(openedWorkbook.Name, 1, Len(copiedFromWorkbookName_FirstCharacters)) = copiedFromWorkbookName_FirstCharacters Then
    Set copiedFromWorkbook = openedWorkbook
    Else
    End If
    End Select
    i = i + 1
    Next openedWorkbook
    '
    Select Case i
    Case Is > 2
    MsgBox "Too many open files!", vbInformation
    Case 1
    MsgBox "No attachment opened!", vbInformation
    Case 2
    answer = MsgBox("Attachment file: " + copiedFromWorkbook.Name, vbYesNo)
    If answer = vbYes Then
    Windows(copiedFromWorkbook.Name).Activate
    Range(copiedFromRangeName).Select
    Selection.Copy
    Windows(copiedToWorkbook.Name).Activate
    Range(copiedToRangeName).Select
    ActiveSheet.Paste
    Else
    Exit Sub
    End If
    End Select

    End Sub

+ 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. [SOLVED] Open Existing File and Copy Range to Current Workbook
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2013, 01:37 PM
  2. [SOLVED] [EXCEL] Open and copy from workbook specified in existing cells / 2010 upgrade problem
    By morten.bay in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2012, 04:20 AM
  3. [EXCEL] Open and copy from workbook specified in existing cells / 2010 upgrade problem
    By morten.bay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2012, 09:07 AM
  4. [SOLVED] Using a macro to copy data from an unsaved, nonactive, varying title workbook
    By tableq in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-24-2012, 06:52 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