+ Reply to Thread
Results 1 to 7 of 7

How do i write code for saving a pdf based on a cell name and also how to auto copy ?

  1. #1
    Registered User
    Join Date
    04-16-2015
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    40

    Angry How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    I have 3 worksheets; REPORT, RECORD, and SHADOW RECORD. Report is filled out by the user and when they fill it in the data appears in SHADOW RECORD. When they click SAVE the data in SHADOW RECORD is copied from shadow record to RECORD. After which, the report that the user fills in is then saved as a pdf with the default name of the Inspection Number.

    However I am having problems writing code for this as I have done this manually and I think it is one of those things where the code is much more efficient than doing it manually. This is what my manual steps look like :

    Please Login or Register  to view this content.
    Basically when I run the macro the information being copied from SHADOW RECORDS to RECORDS is not consistent and when I did it manually I inserted a row manually after I had pasted special (values) into the first row underneath the column titles in row 1. The pdf can be created but the saving of it is difficult as you are having to manually save the document rather than doing it automatically. Should I ditch the manual and go vba ? and what should my code look like?
    Attached Files Attached Files
    Last edited by QuintonMcCloud; 11-24-2015 at 06:25 AM. Reason: code does not comply with forum rules

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi, Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-16-2015
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    40

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi Richard

    Thank you very much for the heads up I think I have wrapped the code now

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi,

    Thanks for editing the code tags.

    Can you just confirm the basic tasks here.
    One task seems to be to copy the shadow record to the record sheet, and the other is to save the pdf file. If so then the following should be sufficient

    Please Login or Register  to view this content.
    Note that it's rarely necessary to .Select and .Activate stuff. Jumping backwards and forewards between VBA and the Excel App to do this carries a time overhead and it's just inefficient.

  5. #5
    Registered User
    Join Date
    04-16-2015
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    40

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi Richard

    Basically the SAVE macro should copy row A2 from SHADOWRECORDS and paste it into RECORD each time a form is filled in and saved.
    Within the SAVE macro after it has copied and pasted only the values in RECORD then it saves Range: C1:Q72 as a pdf and it takes the name of this pdf from the Inspection number cell, 'REPORT'!F7 .

    The problems I can say I have been having are that shadow record is linked to the REPORT hence why you always copy from the shadow however it always works once but not with multiple entries.

    I have put the code you sent me and I have a syntax error when it comes to the following:
    Please Login or Register  to view this content.
    The red part of the code is giving me a syntax error. I am trying to see if its the path that is wrong but it isnt , atleast I dont think ha!.

    Thank you very much for that Richard.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi,

    You should use the sheet VBA code names that I showed in my example instead of the 'Record, 'ShadowRecord'...etc.
    i.e. Sheet2, Sheet3 etc..

    It's good practice to always use the VBA code names since it's all to easy to change the sheet tab names and once you do that the macro will fall over. The VBA code name is the first bit of the sheet description, the tab name is the bit in parentheses. So where you see
    Sheet1(Report) in the VBE the VB code name is Sheet1 and the tab name is Report.

    You should also move the vertical page break on the Report tab otherwise the pdf file will spread over two pages.

  7. #7
    Registered User
    Join Date
    04-16-2015
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    40

    Re: How do i write code for saving a pdf based on a cell name and also how to auto copy ?

    Hi

    Thanks Richard. I am going to try and follow what you have said just now and see if it works thank you . Is this also going to fix the syntax error do you reckon?

    regards

+ 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] Auto Filtering based on Cell Value? Code Required.
    By SharpL in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-22-2014, 04:57 AM
  2. Auto Filtering based on Cell Value? Code Required.
    By SharpL in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-19-2014, 10:01 AM
  3. Replies: 0
    Last Post: 06-11-2013, 05:14 PM
  4. [SOLVED] UserForm in Excel- need to write code to auto fill a text field
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-09-2013, 10:58 AM
  5. [SOLVED] write code to copy a current variables value into next available cell in worksheet
    By damayn83 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2013, 04:32 PM
  6. auto filter event code based on cell two cell value
    By njan1982 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2013, 09:02 AM
  7. how write to rows selected by auto/advanced filter in VBA code
    By xdalibor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2011, 11:28 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