+ Reply to Thread
Results 1 to 2 of 2

Copy Paste Question

  1. #1
    Registered User
    Join Date
    06-13-2005
    Posts
    4

    Copy Paste Question

    I am new with VBA - is the code below copying from Test1 and Test2 to paste into current spreadsheet??


    Why am I getting an error on this line form the code below.




    Workbooks.Open Filename:=ar(i)


    It seems not to see the files I am trying to open????

    _____________________________________________________


    Sub macro2()
    '


    Dim present_workbook As String
    Dim ar As Variant
    ar = Array("D:\Documents and Settings\My Documents\test1.xls ", " D:\Documents and Settings\My Documents\test2.xls ") ' all the spread sheets
    present_workbook = ActiveWorkbook.Name
    For i = 0 To UBound(ar)
    Workbooks.Open Filename:=ar(i)
    temp = ActiveWorkbook.Name
    Range("A1:G1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.End(xlDown).Select
    If (ActiveCell.Row < 65536) Then
    Range("A1:G1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Workbooks(present_workbook).Activate
    Sheets("Sheet1").Select
    Range("A65535").Select
    Selection.End(xlUp).Select
    If (ActiveCell.Row <> 1) Then
    ActiveCell.Offset(1, 0).Select
    End If
    ActiveSheet.Paste
    Application.CutCopyMode = False

    End If
    Workbooks(temp).Activate
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Next
    End Sub

  2. #2
    Dave Peterson
    Guest

    Re: Copy Paste Question

    Yes, it's supposed to copying from the workbooks that are being opened.

    Are you sure that they exist in that location?

    If they don't exist, then you should be getting some error when you run the
    code.

    lcannon wrote:
    >
    > I am new with VBA - is the code below copying from Test1 and Test2 to
    > paste into current spreadsheet??
    >
    > Why am I getting an error on this line form the code below.
    >
    > Workbooks.Open Filename:=ar(i)
    >
    > It seems not to see the files I am trying to open????
    >
    > _____________________________________________________
    >
    > Sub macro2()
    > '
    >
    > Dim present_workbook As String
    > Dim ar As Variant
    > ar = Array("D:\Documents and Settings\My Documents\test1.xls ", "
    > D:\Documents and Settings\My Documents\test2.xls ") ' all the spread
    > sheets
    > present_workbook = ActiveWorkbook.Name
    > For i = 0 To UBound(ar)
    > Workbooks.Open Filename:=ar(i)
    > temp = ActiveWorkbook.Name
    > Range("A1:G1").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.End(xlDown).Select
    > If (ActiveCell.Row < 65536) Then
    > Range("A1:G1").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Copy
    > Workbooks(present_workbook).Activate
    > Sheets("Sheet1").Select
    > Range("A65535").Select
    > Selection.End(xlUp).Select
    > If (ActiveCell.Row <> 1) Then
    > ActiveCell.Offset(1, 0).Select
    > End If
    > ActiveSheet.Paste
    > Application.CutCopyMode = False
    >
    > End If
    > Workbooks(temp).Activate
    > ActiveWorkbook.Save
    > ActiveWorkbook.Close
    > Next
    > End Sub
    >
    > --
    > lcannon
    > ------------------------------------------------------------------------
    > lcannon's Profile: http://www.excelforum.com/member.php...o&userid=24253
    > View this thread: http://www.excelforum.com/showthread...hreadid=378648


    --

    Dave Peterson

+ 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