+ Reply to Thread
Results 1 to 4 of 4

Change data in temporary created file to value

Hybrid View

MagicMan Change data in temporary... 08-27-2019, 07:09 AM
Greg M Re: Change data in temporary... 08-27-2019, 07:20 AM
MagicMan Re: Change data in temporary... 08-27-2019, 07:33 AM
Greg M Re: Change data in temporary... 08-27-2019, 07:48 AM
  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Change data in temporary created file to value

    Hi Folks,

    I have a macro that, using formula generated data from a 'Master' file, generates a 'Temporary' file.

    What I'd like to do is ensure that the data in the temporary file is changed from the formula generated to values. (I can't change the formula or values in the original file).

    This is the code I have that generates the temporary file. Can anyone tell me what code I need to insert where to achieve this please.

    Many thanks.
    Sub Email_Sheet()
    
        Dim oApp As Object
        Dim oMail As Object
        Dim LWorkbook As Workbook
        Dim LFileName As String
        
        
        'Turn off screen updating
        Application.ScreenUpdating = False
        
    '    Last_Sent Macro
    '
    
    '
        Range("I3").Select
        Selection.Copy
        Range("R1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        
        Calculate
        
        'Copy the active worksheet and save to a temporary workbook
        ActiveSheet.Copy
        Set LWorkbook = ActiveWorkbook
    
        'Create a temporary file in your current directory that uses the name
        ' of the sheet as the filename
        LFileName = LWorkbook.Worksheets(1).Name
        On Error Resume Next
        'Delete the file if it already exists
        Kill LFileName
        On Error GoTo 0
        'Save temporary file
        LWorkbook.SaveAs Filename:=Range("I2").Value, FileFormat:=xlOpenXMLWorkbookMacroEnabled
        
        'Create an Outlook object and new mail message
        Set oApp = CreateObject("Outlook.Application")
        Set oMail = oApp.CreateItem(0)
        
        'Set mail attributes (uncomment lines to enter attributes)
        ' In this example, only the attachment is being added to the mail message
        With oMail
            .SentOnBehalfOfName = "To be confirmed"
            .To = "Firstname.lastname@gcompany.co.uk"
    '        .cc = "Fred.Bloggs@Company.co.uk"
            .Subject = "Subject header Message Line 1" & Range("I3")
            .body = "Message Line 2"
            .Attachments.Add LWorkbook.FullName
            .Display
        End With
    
        'Delete the temporary file and close temporary Workbook
        LWorkbook.ChangeFileAccess Mode:=xlReadOnly
        Kill LWorkbook.FullName
        LWorkbook.Close SaveChanges:=False
    
        'Turn back on screen updating
        Application.ScreenUpdating = True
        Set oMail = Nothing
        Set oApp = Nothing
        
    '    Call MarkIDsAfterEmailSent
     
    End Sub

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Change data in temporary created file to value

    Hi there,

    This is just a knee-jerk (and untested) response, but try adding the highlighted code to your own version:

    
    
    Sub Email_Sheet()
    
        Dim oApp As Object
        Dim oMail As Object
        Dim LWorkbook As Workbook
        Dim LFileName As String
        
        
        'Turn off screen updating
        Application.ScreenUpdating = False
        
    '    Last_Sent Macro
    '
    
    '
        Range("I3").Select
        Selection.Copy
        Range("R1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        
        Calculate
        
        'Copy the active worksheet and save to a temporary workbook
        ActiveSheet.Copy
        Set LWorkbook = ActiveWorkbook
    
        With ActiveSheet.UsedRange.Cells
            .Value = .Value
        End With
    
        'Create a temporary file in your current directory that uses the name
        ' of the sheet as the filename
        LFileName = LWorkbook.Worksheets(1).Name

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Change data in temporary created file to value

    HI Greg,

    That's brilliant, it works. (Rep Added - for this alone!)

    However, I've also discovered I've got two buttons, with macro's assigned, that also cross reference the original file

    Rectangle:Rounded Corners 1
    Rectangle:Rounded Corners 2

    I don't need them in the copied file. Are you able to come up with a code to delete them please.

    Many thanks

    Terry

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Change data in temporary created file to value

    Hi again,

    Many thanks for your very prompt feedback and also for the Reputation increase - much appreciated!

    To remove the buttons try adding the highlighted code as shown below:

    
        Calculate
        
        'Copy the active worksheet and save to a temporary workbook
        ActiveSheet.Copy
        Set LWorkbook = ActiveWorkbook
    
        With ActiveSheet.UsedRange.Cells
            .Value = .Value
        End With
    
        ActiveSheet.Shapes("Rounded Rectangle 1").Delete
        ActiveSheet.Shapes("Rounded Rectangle 2").Delete
    
        'Create a temporary file in your current directory that uses the name
        ' of the sheet as the filename
        LFileName = LWorkbook.Worksheets(1).Name

    Hope this helps - as before, please let me know how you get on.

    Best regards,

    Greg M

+ 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. Save as a temporary file and paste automatically once destination file is not read only
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2019, 03:35 AM
  2. Change log file created using VBA
    By public in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2019, 05:52 AM
  3. Replies: 10
    Last Post: 10-05-2016, 08:16 AM
  4. [SOLVED] My formula is looking up a temporary file when I do not want it to
    By jbeets in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-04-2015, 07:49 AM
  5. [SOLVED] How to extract web data into a temporary file that would be used as input variables
    By lubbamkt in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-12-2014, 05:31 PM
  6. Change the Name of a Temporary File
    By whisperinghill in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-30-2007, 03:26 PM
  7. [SOLVED] Change File DATE created & modified
    By Don Guillett in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2005, 05:06 PM

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