If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Macro help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-11, 16:10
mstevenson21 mstevenson21 is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
Macro help

Hi guys,
I'm only new to creating macros but I am trying to make one which can open a number of files save them as txt files and then close them. Everytime it asks me if I want to save the changes to the txt file and I can't workout how to stop this happening. If anyone could help it would be very much appreciated!

Code:
Sub SaveAsTextFile()
    
    Dim filenames As Variant
   
   ' set the array to a variable and the True is for multi-select
   filenames = Application.GetOpenFilename(, , , , True)

      counter = 1

      ' ubound determines how many items in the array
      While counter <= UBound(filenames)

         'Opens the selected files
         Workbooks.Open filenames(counter)

Dim strDocName As String
Dim intPos As Integer

'Find position of extension in file name
strDocName = ActiveWorkbook.Name
intPos = InStrRev(strDocName, ".")

'Strip off extension and add ".txt" extension
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".txt"

'Save file with new extension
ActiveWorkbook.saveas Filename:= _
strDocName, FileFormat:= _
xlText, CreateBackup:=False


ActiveWorkbook.Close


'increment counter
         counter = counter + 1

      Wend

End Sub

Last edited by mstevenson21; 07-09-11 at 16:34.
Reply With Quote
  #2 (permalink)  
Old 07-11-11, 08:03
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

You could try

Code:
'Save file with new extension

Application.DisplayAlerts = False

ActiveWorkbook.saveas Filename:= _
strDocName, FileFormat:= _
xlText, CreateBackup:=False

Application.DisplayAlerts = True
and see if that does it!

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On