Results 1 to 3 of 3

Remove message box from code

Threaded View

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

    Remove message box from code

    Hi Folks,

    I have a workbook that I use as a template to export data to a csv (for uploading to a different system)

    Following research I uploaded code. However, at the time, I had to manually select the cells for export. I've managed to change that (with the Used Range)

    Can anyone help me so to remove the Input box and it just execute the code

    Here's the code: (I've highlighted in Red the bit I want to get rid of)
    Public Sub ExcelRowsToCSV()
     
      Dim iPtr As Integer
      Dim sFileName As String
      Dim intFH As Integer
      Dim aRange As Range
      Dim iLastColumn As Integer
      Dim oCell As Range
      Dim iRec As Long
      Dim ws As Worksheet
      
      Set ws = ThisWorkbook.Worksheets(1)
      ws.UsedRange.Select
     
     
    
      Set aRange = Application.InputBox("Select a range:-", , Selection.Address, , , , , Type:=8)
     iLastColumn = aRange.Column + aRange.Columns.Count - 1
      
      iPtr = InStrRev(ActiveWorkbook.FullName, ".")
      sFileName = Left(ActiveWorkbook.FullName, iPtr - 1) & ".csv"
      sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, FileFilter:="CSV (Comma delimited) (*.csv), *.csv")
      If sFileName = "False" Then Exit Sub
        
      Close
      intFH = FreeFile()
      Open sFileName For Output As intFH
      
      iRec = 0
      For Each oCell In aRange
        If oCell.Column = iLastColumn Then
          Print #intFH, oCell.Value
          iRec = iRec + 1
        Else
          Print #intFH, oCell.Value; ",";
        End If
      Next oCell
       
      Close intFH
      
      MsgBox "Finished: " & CStr(iRec) & " records written to " _
         & sFileName & Space(10), vbOKOnly + vbInformation
     
    
     
    End Sub
    I still need the SaveAs dialog box to open and, being honest, I can live without the final message box.

    So if any of you geniuses out there have a smarter way of achieving the same ends, I'd be very grateful.

    Ta!

    MM
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to remove map error message
    By Statto in forum Excel General
    Replies: 2
    Last Post: 11-02-2020, 03:55 PM
  2. How to remove this message?
    By terrypin in forum Excel General
    Replies: 15
    Last Post: 12-27-2017, 06:26 AM
  3. How to remove this message
    By beekobeeko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2016, 07:34 AM
  4. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  5. Formula to remove Message
    By elewis1220 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-29-2014, 12:29 PM
  6. [SOLVED] how to remove the message-pls sugg
    By VbUser25 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2005, 09:06 PM
  7. how to remove the message-pls sugg
    By VbUser25 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2005, 10: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