Hi,
Been trying to put VBA together to simply save a CSV as an XLS. I don't get an error (technically?). However, my personal macro workbook seems to disappear and I get a whole bunch of code that is completely over beyond basic head.
Is everything I'm doing completely wrong an absolute mess? Is there a better way?
Thanks!
Below is what I'm trying to use:
Below is what happens once I run the above:
Been trying to put VBA together to simply save a CSV as an XLS. I don't get an error (technically?). However, my personal macro workbook seems to disappear and I get a whole bunch of code that is completely over beyond basic head.
Is everything I'm doing completely wrong an absolute mess? Is there a better way?
Thanks!
Below is what I'm trying to use:
VBA Code:
Sub SaveAsToMyDocuments()
Dim DTAddress As String
Dim FileName As String
Dim FullyQualifiedFileName As String
'Build the Workbook name to save as CSV format File
FileName = ActiveWorkbook.Name
FileName = Left(FileName, InStr(FileName, ".")) & "xls"
'Build the fully-qualified Workbook "save" path
FullyQualifiedFileName = DTAddress & FileName
'Switch Off all Application alerts before saving (in case the file already exists etc.)
Application.DisplayAlerts = False
'Save the current active sheet as a XLS file to the user's Documents
ActiveWorkbook.SaveAs FileName:=FullyQualifiedFileName, FileFormat:=xlExcel8
'Close the original Workbook without saving changes
ThisWorkbook.Close savechanges:=False
'Switch all Application alerts back on before exiting
Application.DisplayAlerts = True
End Sub
Below is what happens once I run the above:
VBA Code:
Const sResourcePrefix As String = "RES_"
'Get Culture
Private Function GetATPUICultureTag() As String
Dim shTemp As Worksheet
Dim sCulture As String
Dim sSheetName As String
sCulture = Application.International(xlUICultureTag)
sSheetName = sResourcePrefix + sCulture
On Error Resume Next
Set shTemp = ThisWorkbook.Worksheets(sSheetName)
On Error GoTo 0
If shTemp Is Nothing Then sCulture = GetFallbackTag(sCulture)
GetATPUICultureTag = sCulture
End Function
'Entry point for RibbonX button click
Sub ShowATPDialog(control As IRibbonControl)
Application.Run ("fDialog")
End Sub
'Callback for RibbonX button label
Sub GetATPLabel(control As IRibbonControl, ByRef label)
label = ThisWorkbook.Sheets(sResourcePrefix + GetATPUICultureTag()).Range("RibbonCommand").Value
End Sub
'Callback for screentip
Public Sub GetATPScreenTip(control As IRibbonControl, ByRef label)
label = ThisWorkbook.Sheets(sResourcePrefix + GetATPUICultureTag()).Range("ScreenTip").Value
End Sub
'Callback for Super Tip
Public Sub GetATPSuperTip(control As IRibbonControl, ByRef label)
label = ThisWorkbook.Sheets(sResourcePrefix + GetATPUICultureTag()).Range("SuperTip").Value
End Sub
Public Sub GetGroupName(control As IRibbonControl, ByRef label)
label = ThisWorkbook.Sheets(sResourcePrefix + GetATPUICultureTag()).Range("GroupName").Value
End Sub
'Check for Fallback Languages
Private Function GetFallbackTag(szCulture As String) As String
'Sorted alphabetically by returned culture tag, then input culture tag
Select Case (szCulture)
Case "rm-CH"
GetFallbackTag = "de-DE"
Case "ca-ES", "ca-ES-valencia", "eu-ES", "gl-ES"
GetFallbackTag = "es-ES"
Case "lb-LU"
GetFallbackTag = "fr-FR"
Case "nn-NO"
GetFallbackTag = "nb-NO"
Case "be-BY", "ky-KG", "tg-Cyrl-TJ", "tt-RU", "uz-Latn-UZ"
GetFallbackTag = "ru-RU"
Case Else
GetFallbackTag = "en-US"
End Select
End Function