+ Reply to Thread
Results 1 to 2 of 2

VBA Code Error when I copy and paste from another workbook

  1. #1
    Registered User
    Join Date
    07-16-2015
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    3

    VBA Code Error when I copy and paste from another workbook

    I have written a code that takes multiple (up to 320 sheets) and simply saves them in specified folder as a PDF if data is present in a specific cell. It works great when we manually input the data, however when we copy the exact same data from another workbook it gives me a runtime error. Please note that the individual worksheets are hard-coded to a source worksheet that populates the input data. Here is the code I am using below:

    Sub Sutherland_PDF()


    Dim FolderPath As String
    Dim i As Integer
    Dim wb As ThisWorkbook

    Set wb = ActiveWorkbook

    FolderPath = "S:\_UCC Folder\UCCResults\Lindsay\"
    Windows("UCC PDF Master Lindsay.xlsm").Activate
    For i = 3 To Worksheets.Count

    ThisWorkbook.Worksheets(i).Range("C17").WrapText = True

    'since you are linking the data on the main excel sheet. It is placing a zero in all cells that have no data
    'go to view and select immediate window then run the program you will see all of the pages that have something other than 0 listed
    If ThisWorkbook.Worksheets(i).Range("C17").Value <> 0 Then


    'Creates PDF from selected sheet
    ThisWorkbook.Worksheets(i).ExportAsFixedFormat Type:=xlTypePDF, FileName:=FolderPath & ThisWorkbook.Worksheets(i).Name & "-" & ThisWorkbook.Worksheets(i).Range("D55").Value & "-" & ThisWorkbook.Worksheets(i).Range("C55").Value & ".pdf", OpenAfterPublish:=False




    End If



    Next




    MsgBox "All Files have been saved to your S-Drive Folder. Have a Great Day!"



    End Sub

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: VBA Code Error when I copy and paste from another workbook

    Please observe forum rules and enclose code in code tags.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA - Excel code to copy and paste from several Sharepoint workbook files to one workbook
    By TraceyPatterson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2015, 06:45 AM
  2. Copy paste value - Macro code error
    By Dial1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2014, 05:27 PM
  3. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  4. Macro Code Copy Paste Error
    By FLani in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-21-2013, 10:54 PM
  5. Copy paste code error
    By shaukat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2011, 05:12 PM
  6. Compile error in copy/paste code
    By carbonboywonder in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2010, 07:46 AM
  7. copy and paste using code from workbook to workbook
    By bigdaddy3 in forum Excel General
    Replies: 2
    Last Post: 09-14-2005, 07:05 AM

Tags for this Thread

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