+ Reply to Thread
Results 1 to 11 of 11

.xls to .txt file auto update on save

  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Unhappy .xls to .txt file auto update on save

    Good Morning,

    I am trying to change the file location that the file is created in from "MyDoccuments" to "\\prod\userdata\IS-3\FSD-SysDev\HD\MonthendHosp\Monthend Automation processes "

    I am also trying to get the Before save function to work on my code so that it automatically updates the .txt file when the user hits save.

    Here is what I have:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
    Cancel As Boolean)
    a = MsgBox("Do you really want to save the workbook?", vbYesNo)
    If a = vbNo Then Cancel = True
    Next N
    Option Explicit
    Sub SaveAsPipeDelimited()
    Const DELIMITER As String = "|"
    Dim myRecord As Range
    Dim myField As Range
    Dim nFileNum As Long
    Dim sOut As String
    Dim N As Long
    nFileNum = FreeFile
    Open "EOMStatsForKirk.txt" For Output As #nFileNum
    For N = 1 To ActiveSheet.UsedRange.Rows.Count
    Print #nFileNum, Cells(N, 1) & "|" & Cells(N, 3) & "|" & Cells(N, 5) & "|" & Cells(N, 12)
    Next N
    Close #nFileNum
    End Sub


    Please advise when possible. I need to have this completed today! Thank you so much for your help in advance.

  2. #2
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: .xls to .txt file auto update on save

    First please make sure to post any code in the code tags (#)

    In your code the first part seems a bit odd , i assume you did not coy everything
    Please Login or Register  to view this content.
    then for the location of your textfile , you use
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved , to mark your thread as Solved select Thread Tools and click Mark thread as Solved.

    I can't read the mind of my wife so then I get picture but no sound .... and then I mostly get the idea, same goes here picture your outcome and I get the idea.

  3. #3
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: .xls to .txt file auto update on save

    Thank you so much for the help. That did change the file location for the created text, howver, the .txt file still will not update on save. I have to run the macro to get it to update.

    Do you happen to know how to do this?

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: .xls to .txt file auto update on save

    oh i dont know how your excel file is build but there is a faster way then writing the text file this way
    Please Login or Register  to view this content.
    Last edited by hulpeloos; 08-16-2013 at 08:52 AM. Reason: removed a "

  5. #5
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: .xls to .txt file auto update on save

    Quote Originally Posted by lengwer View Post
    Thank you so much for the help. That did change the file location for the created text, howver, the .txt file still will not update on save. I have to run the macro to get it to update.

    Do you happen to know how to do this?
    in red :
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Talking Re: .xls to .txt file auto update on save

    The message box is not needed for the _Before save and I am not sure if I need to save as the workbook_beforesave or the Sheet1_Beforesave. The ultimate goal is to have the .txt file updated without prompting the user "behind the scenes". The code is supposed to look like this:

    Please Login or Register  to view this content.
    Found here :
    HTML Code: 
    I have the concept but I am not sure how to tie it together.

    Thanks again for all your help.

  7. #7
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: .xls to .txt file auto update on save

    I have to have the .txt file to report as pipe delimited. I am having the code pull out columns A,C,E& L and report as a pipe delimited .txt file. The text file has to update behind the scenes when the user hits save. I added the code in red and it still would not update the .xtx file without me having to run the macro.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: .xls to .txt file auto update on save

    If you do not want users to be prompted


    Please Login or Register  to view this content.
    Last edited by hulpeloos; 08-16-2013 at 09:31 AM.

  9. #9
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: .xls to .txt file auto update on save

    If I replace my code with this it does not create a .txt file at all and there is not a macro to run.

  10. #10
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: .xls to .txt file auto update on save

    bold needs rectification
    Please Login or Register  to view this content.
    and i forgot to mention the most logic part , this needs to be copied under "ThisWorkbook" , not in a Module or UserForm and each time you click to save it gets trigerd.

    look up in previous post in bold (i cut to much when posting it originaly)
    a = vbNo
    If a = vbNo Then Cancel = True
    Last edited by hulpeloos; 08-16-2013 at 09:32 AM. Reason: code part

  11. #11
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: .xls to .txt file auto update on save

    If it helps my code is not in the "ThisWorkbook" module it is in "Sheet1" Or " EOM Stats"(As it is named)

  12. #12
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: .xls to .txt file auto update on save

    I moved the code to "ThisWorkbook" and the code works perfectly! Thank you for all of your help!!

+ 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 Save Shared Workbook and Update Display
    By Logit in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-02-2014, 02:29 AM
  2. Auto-install & auto-update add-in using executable file
    By bambaataa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2013, 12:17 AM
  3. Need to auto increment and update PO # and save file as cells H7,J7, and A14
    By carson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-08-2012, 01:35 PM
  4. Auto-Install/Auto-Update Add-In Using Executable File
    By bambaataa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 10:36 AM
  5. [SOLVED] Auto Update / Save
    By Chewy in forum Excel General
    Replies: 1
    Last Post: 02-15-2005, 06:45 PM

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