+ Reply to Thread
Results 1 to 2 of 2

My Macro stops

  1. #1
    Bobby
    Guest

    My Macro stops

    Hello
    This is my code...

    ChDir "C:\Temp"
    Workbooks.OpenText Filename:="C:\Temp\myfile.txt", Origin:=xlWindows, _
    StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
    Array(8, _
    1), Array(12, 1), Array(17, 1), Array(21, 1), Array(29, 1),
    Array(38, 1), Array(46, 1), _
    Array(50, 1), Array(58, 1), Array(67, 1))
    Range("A2").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Windows("daily.xls").Activate
    Sheets("table").Select
    Worksheets("table").Unprotect
    Range("t2").Select
    ActiveSheet.Paste

    It was working fine until I added sheet protection and the
    Worksheets("table").Unprotect part.

    Now I get "Paste method od Worksheet class failed."
    What is causing this and how do I fix it?

    Thanks!

  2. #2
    Tom Ogilvy
    Guest

    Re: My Macro stops

    Dim bk as Workbook, rng as Range
    ChDir "C:\Temp"
    set bk = Workbooks.OpenText( Filename:="C:\Temp\myfile.txt", _
    Origin:=xlWindows, _
    StartRow:=1, _
    DataType:=xlFixedWidth, _
    FieldInfo:=Array(Array(0, 1), _
    Array(8,1), Array(12, 1), Array(17, 1), _
    Array(21, 1), Array(29, 1), Array(38, 1), _
    Array(46, 1), Array(50, 1), Array(58, 1), _
    Array(67, 1))
    set rng = activesheet.Range("A1").CurrentRegion
    set rng = rng.offset(1,0).Resize(rng.rows.count-1)
    Windows("daily.xls").Activate
    Sheets("table").Select
    Worksheets("table").Unprotect
    rng.copy Destination:=Range("T2")

    --
    Regards,
    Tom Ogilvy


    "Bobby" <Bobby@discussions.microsoft.com> wrote in message
    news:ABCDC40C-9457-4AEB-9C7E-9E16DD9E49F5@microsoft.com...
    > Hello
    > This is my code...
    >
    > ChDir "C:\Temp"
    > Workbooks.OpenText Filename:="C:\Temp\myfile.txt", Origin:=xlWindows,

    _
    > StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
    > Array(8, _
    > 1), Array(12, 1), Array(17, 1), Array(21, 1), Array(29, 1),
    > Array(38, 1), Array(46, 1), _
    > Array(50, 1), Array(58, 1), Array(67, 1))
    > Range("A2").Select
    > Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    > Selection.Copy
    > Windows("daily.xls").Activate
    > Sheets("table").Select
    > Worksheets("table").Unprotect
    > Range("t2").Select
    > ActiveSheet.Paste
    >
    > It was working fine until I added sheet protection and the
    > Worksheets("table").Unprotect part.
    >
    > Now I get "Paste method od Worksheet class failed."
    > What is causing this and how do I fix it?
    >
    > Thanks!




+ 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