help with vba

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
548
Office Version
  1. 365
Platform
  1. Windows
hi

i need help adding somwthinf to thios vba

Code:
sub SaveFile2222()
Dim ans As Long
Dim sSaveAsFilePath As String


mybook = ActiveWorkbook.Name
    On Error GoTo ErrHandler:
If Len(mybook) > 25 Then
mybook = Left(mybook, 25)
End If
    sSaveAsFilePath = "C:\Users\jack\Desktop\AAAA\" & Replace(mybook, ".xlsx", "") & ".txt"






    If Dir(sSaveAsFilePath) <> "" Then
        ans = MsgBox("File " & sSaveAsFilePath & " exists.  Overwrite?", vbYesNo + vbExclamation)
        If ans <> vbYes Then
            Exit Sub
        Else
            Kill sSaveAsFilePath
        End If
    End If
    ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows




My_Exit:
Exit Sub




ErrHandler:
MsgBox Err.Description
Resume My_Exit
End Sub
From my understating is, that if you get the MSG box asking if you want to override it, and you hit "NO" it doesn't override it

I would like that if you hit "no" the save as dialog box should open up and you should be able to change the name of the file

Also there should be a check that if you name the file and you attempt to save it and the file name is more then 25 charterers you should not be able to save it

It should also only allow you to save it as a .txt format

Any help is greatly appreciated
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
try something like this:
Code:
Sub SaveFile2222()
Dim ans As Long
Dim sSaveAsFilePath As String




mybook = ActiveWorkbook.Name
    On Error GoTo ErrHandler:
If Len(mybook) > 25 Then
mybook = Left(mybook, 25)
End If
    sSaveAsFilePath = "C:\Users\jack\Desktop\AAAA\" & Replace(mybook, ".xlsx", "") & ".txt"












    If Dir(sSaveAsFilePath) <> "" Then
        ans = MsgBox("File " & sSaveAsFilePath & " exists.  Overwrite?", vbYesNo + vbExclamation)
        If ans <> vbYes Then
         newnam = InputBox("Enter Name of file, 25 chars Max")
         sSaveAsFilePath = "C:\Users\jack\Desktop\AAAA\" & newnam & ".txt"
           
        Else
            Kill sSaveAsFilePath
        End If
    End If
    ActiveWorkbook.SaveAs sSaveAsFilePath, FileFormat:=xlTextWindows








My_Exit:
Exit Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top