+ Reply to Thread
Results 1 to 4 of 4

Macro opens created file.

  1. #1
    Registered User
    Join Date
    06-18-2021
    Location
    Bloemfontein, south Africa
    MS-Off Ver
    2019
    Posts
    65

    Macro opens created file.

    Hi Everyone,

    I have the following macro assigned to a button in my worksheet.

    Sub saveAsPRNFile()
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWB As Workbook, srcWS As Worksheet
    Set srcWB = ThisWorkbook
    Set srcWS = srcWB.Sheets("Sheet1")
    LastRow = srcWS.Range("K" & srcWS.Rows.Count).End(xlUp).Row
    Workbooks.Add
    srcWS.Range("K12:K" & LastRow).Copy
    Range("A1").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\iq2000\4custa.prn", FileFormat:=xlTextPrinter, CreateBackup:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub


    Is there a way I can run it without the file being opened afterwards?

    It works 100% but then after running it sometimes happens that a key get pressed by the operator and the the file doesn't work

    Thank you

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Macro opens created file.

    Hi,
    Add the following after the save as line
    Please Login or Register  to view this content.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    06-18-2021
    Location
    Bloemfontein, south Africa
    MS-Off Ver
    2019
    Posts
    65

    Re: Macro opens created file.

    Hi Keebellah,

    Works like a dream thanks a million

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Macro opens created file.

    Good to hear,
    Happy coding ...

+ 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. Macro in Template opens new workbook or macro file not found error
    By CarlThad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2017, 04:02 PM
  2. Macro created in .xlsm file isn't there next day after file is saved...halp pls!
    By Faintkitara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2015, 10:17 AM
  3. Need macro that opens .txt file in excel, run macros and save file in batch
    By khalidness in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2014, 11:00 AM
  4. macro that opens a any csv file within a directory
    By drobinson782001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2013, 11:55 AM
  5. run a macro when a file opens
    By caliskier in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-02-2008, 03:54 PM
  6. How to run a macro when file opens???
    By Shane R. Pouch in forum Excel General
    Replies: 8
    Last Post: 06-30-2006, 08:15 AM
  7. [SOLVED] Why it Opens Macro File
    By [email protected] in forum Excel General
    Replies: 0
    Last Post: 06-09-2006, 05:35 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