+ Reply to Thread
Results 1 to 2 of 2

problem importing data from another file

  1. #1
    Qaspec
    Guest

    problem importing data from another file

    I am trying to run one macro but get an error message fron another macro in
    the same worksheet. Here is the macro I am running

    Private Sub Import1_Click()

    Dim wba As Workbook

    Dim ls_Rangestringa As String

    Dim ll_Rownumbera As Long

    ll_Rownumbera = 4

    ls_Rangestringa = "B" + CStr(ll_Rownumbera)

    Application.ScreenUpdating = False ' turn off the screen updating
    Set wba = Workbooks.Open("H:\My
    Documents\AttendanceUpdate\NewEmployeeData.xls")

    With ThisWorkbook.Worksheets("Emp1")
    .Range("B4").Value =
    wba.Worksheets("NewData").Range(ls_Rangestringa).Value

    wba.Close False
    Application.ScreenUpdating = True ' turn on the screen updating

    End With
    End Sub

    When I run this macro I get an error message
    "Subscript out of range" then "Not enough system resources"

    Here is the code the debugger highlights

    Private Sub Worksheet_Change(ByVal Target As Range)

    Worksheets("Main").emp1.Caption = Worksheets("Emp1").Range("B4").Value

    End Sub

    Thanx for any help.





  2. #2
    Tom Ogilvy
    Guest

    Re: problem importing data from another file

    Private Sub Import1_Click()

    Dim wba As Workbook

    Dim ls_Rangestringa As String

    Dim ll_Rownumbera As Long

    ll_Rownumbera = 4

    ls_Rangestringa = "B" + CStr(ll_Rownumbera)

    Application.ScreenUpdating = False ' turn off the screen updating
    On Error goto ErrHandler
    Application.EnableEvents = False
    Set wba = Workbooks.Open("H:\My
    Documents\AttendanceUpdate\NewEmployeeData.xls")


    With ThisWorkbook.Worksheets("Emp1")
    .Range("B4").Value =
    wba.Worksheets("NewData").Range(ls_Rangestringa).Value

    wba.Close False

    Application.ScreenUpdating = True ' turn on the screen updating

    End With
    ErrHandler:
    Application.EnableEvents = True
    End Sub

    or perhaps

    Private Sub Worksheet_Change(ByVal Target As Range)

    ThisWorkbook. Worksheets("Main").emp1.Caption = _
    ThisWorkbook.Worksheets("Emp1").Range("B4").Value

    End Sub


    --
    Regards,
    Tom Ogilvy


    "Qaspec" <Qaspec@discussions.microsoft.com> wrote in message
    news:BD9A0AC1-6C23-4AF2-8B77-2F5BF366F0BE@microsoft.com...
    > I am trying to run one macro but get an error message fron another macro

    in
    > the same worksheet. Here is the macro I am running
    >
    > Private Sub Import1_Click()
    >
    > Dim wba As Workbook
    >
    > Dim ls_Rangestringa As String
    >
    > Dim ll_Rownumbera As Long
    >
    > ll_Rownumbera = 4
    >
    > ls_Rangestringa = "B" + CStr(ll_Rownumbera)
    >
    > Application.ScreenUpdating = False ' turn off the screen updating
    > Set wba = Workbooks.Open("H:\My
    > Documents\AttendanceUpdate\NewEmployeeData.xls")
    >
    > With ThisWorkbook.Worksheets("Emp1")
    > .Range("B4").Value =
    > wba.Worksheets("NewData").Range(ls_Rangestringa).Value
    >
    > wba.Close False
    > Application.ScreenUpdating = True ' turn on the screen updating
    >
    > End With
    > End Sub
    >
    > When I run this macro I get an error message
    > "Subscript out of range" then "Not enough system resources"
    >
    > Here is the code the debugger highlights
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Worksheets("Main").emp1.Caption = Worksheets("Emp1").Range("B4").Value
    >
    > End Sub
    >
    > Thanx for any help.
    >
    >
    >
    >




+ 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