+ Reply to Thread
Results 1 to 5 of 5

My macro won't copy values and formats

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    3

    My macro won't copy values and formats

    Hi,
    I am trying to copy data from a closed workbook into another but the macroonly copies the data/values and does not copy the formats. I am using the following code to paste the data: PasteSpecial xlPasteValues - i have tried changing this to PasteSpecial xlPasteFormats and also PasteSpecial xlPasteAll and none of these will paste the formats Am i doing someething wrong?

    Any help would be greatly appreciated.

    Thanks,
    Taffy B

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: My macro won't copy values and formats

    Can you post the code?

    Using xlPasteValue will only paste value, but xlPasteAll should paste values, formats etc
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: My macro won't copy values and formats

    Quote Originally Posted by Norie View Post
    Can you post the code?

    Using xlPasteValue will only paste value, but xlPasteAll should paste values, formats etc
    here is the code I am trying to use - it is a copy of some code i saw on forum :
    Sub GetLocalFile()
    Application.ScreenUpdating = False
    On Error Resume Next

    'Call the macro GetRange
    GetRange "C:\Documents and Settings\anthony.barker\Desktop", "TONY B Copy Of Trainers Availability 2013.xls", _
    "Schedule", "A1:EZ12", _
    Sheets("Schedule").Range("A1")

    On Error GoTo 0
    Application.ScreenUpdating = True

    End Sub


    'Main macro


    Sub GetRange(FilePath As String, FileName As String, SheetName As String, _
    SourceRange As String, DestRange As Range)

    Dim Start

    'Go to the destination range
    Application.Goto DestRange

    'Resize the DestRange to the same size as the SourceRange
    Set DestRange = DestRange.Resize(Range(SourceRange).Rows.Count, _
    Range(SourceRange).Columns.Count)

    'Add formula links to the closed file
    With DestRange
    .FormulaArray = "='" & FilePath & "/[" & FileName & "]" & SheetName _
    & "'!" & SourceRange

    'Wait
    Start = Timer
    Do While Timer < Start + 2
    DoEvents
    Loop

    'Make values from the formulas
    .Copy
    .PasteSpecial xlPasteValues
    .Cells(1).Select
    Application.CutCopyMode = False
    End With
    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: My macro won't copy values and formats

    That code doesn't really copy and paste from the closed workbook.

    It creates formulas/links to the closed workbook then copies those formulas and pastes their values.

    If you want to copy with formats you'll need to open the workbook.

    That would only take a few lines of code.

    PS Can you add code tags to the code? It's hard to tell when one sub ends and the other begins.

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: My macro won't copy values and formats

    Many thanks sfor the swift response - sorry for not using tags. I will try again but following your suggestion re opening the file instead.

    Taffy b

+ 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