+ Reply to Thread
Results 1 to 3 of 3

Open New File & Copy To Existing File

  1. #1
    Registered User
    Join Date
    10-19-2005
    Posts
    45

    Open New File & Copy To Existing File

    Hi all,

    I have set up a spreadsheet in which the user clicks an 'IMPORT DATA' button (which I created) that opens a userform. In this userform the user selects which day of the month they are importing the data for and clicks OK (e.g. 1st, 2nd, 3rd etc.).

    The OK button runs the getopenfilename command so that the user can select the file that they need to open.

    In the spreadsheet that contains the button, I have created a worksheet for each day of the month (e.g. 1st, 2nd, 3rd etc.).

    What I want to occur is that when the file is opened and formatted (by the macro) it is then pasted into the appropriate worksheet (as indicated in the userform) in the spreadsheet from which the macro was run.

    The problem is that the original spreadsheet will be saved as a different file name each month and therefore I cannot use the file name as a target in which to paste the data to.

    I need to know how I can get the macro to recognise where the macro is run from and paste back to it rather than just pasting to a set file name...... can this be done?

    Here is my code:

    Sub OKButton_Click()

    If ComboBox1.Value = "1" Then
    Dim sFile As String
    sFile$ = Application _
    .GetOpenFilename("")

    Workbooks.Open filename:=sFile

    SkillsetGOS
    Cells.Select
    Selection.Copy
    Windows("Delays & GOS Report in progress.xls").Activate
    Sheets("1st").Select
    Cells.Select
    ActiveSheet.Paste
    Unload Me
    Else

    MsgBox "Please Select a Number Between 1 & 31"

    End If

    End Sub

    Any help would be greatly appreciated.

    Cheers,

    Pedros.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Firstly, you should wrap your code with code tags when posting to the Forum.

    Your code needs considerable work - you don't specify a worksheet to select, what if it opens on the wrong sheet?

    What is SkillsetGOS?

    If you name your sheets 1,2,3 etc then it would be simpler to copt to the correct sheet, although I can't understand why you need to do this

    Is the combobox used to select the day of the month?
    Last edited by royUK; 06-14-2007 at 03:11 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    10-19-2005
    Posts
    45
    SkillsetGOS is anothe macro that formats the file that has been opened i.e. strips irrelevant data and formats the data ready for lookups. It is not relevant to my question and is working well.

    As for the code needing work...... that is why I am here..... to get some help with it!!

    I am happy to change the names of the sheets if that would help in anyway, that is not an issue.

    The reason I want to do it is that this spreadsheet will be populated daily with data and within the spreadsheet will be a series of reports that summarise the data from each individual day.

    Hope this clears up a few issues.

    cheers,
    Pedros.

+ 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