VBA-Excel weird behaviour on .RANGE(“B3”).Value – Read On
Using the following statements- when the SAVE dialog box appears, the filename is not pre-populated.
B3 is the filename and defined as General in the Excel spreadsheet.
Dim csv_fileName ‘As String (tried Variant as well)
‘ Build the Export File
csv_fileName = create_csv.Range(“B3”).Value & “.csv”
However, if I add a string value in front, then it works
csv_fileName = “anything” & create_csv.Range(“B3”).Value & “.csv”
Sub ExportToCSVFile()
Dim cell As Range
Dim colIndex As Long
Dim colMax As Integer
Dim create_csv As Worksheet
Dim csv_fileName As String
Dim currentUser As String
Dim delimiter As String
Dim extractedCount As Integer
Dim line As String
Dim oneDrivePath As String
Dim myChoicePath As String
Dim productToHelium_ws As String
Dim rng As Range
Dim rowIndex As Long
Dim spDirectory As String
Dim src_ws As Worksheet
Dim stream As Object ‘ ADODB.Stream
On Error GoTo ErrorHandler
‘ Set the maximum number of columns to extract
colMax = 3
‘ Set the worksheet location for the input variables
Set create_csv = ThisWorkbook.Sheets(“Create_CSV”)
‘ Build the Export File
csv_fileName = create_csv.Range(“B3”).Value & “.csv”
‘ Get the output Directory
myChoicePath = create_csv.Range(“B7”).Value
‘ Set the name of the source worksheet that holds the data for export
Set src_ws = ThisWorkbook.Sheets(“sheet2”)
‘
‘ Define the file path for the CSV file
‘ The user must have created a shortcut link to the SharePoint location. This is explained in the create_csv worksheet.
‘
If myChoicePath = “My Choice” Then
filePath = Application.GetSaveAsFilename(InitialFileName:=csv_fileName, FileFilter:=”CSV Files (*.csv), *.csv”)
‘ Check if user cancelled the Save As dialog
If filePath = “False” Then
Exit Sub
Else ‘ assume we have a SharePoint location chosen. C18 is the SP location
.
.
.
Using the following statements- when the SAVE dialog box appears, the filename is not pre-populated. B3 is the filename and defined as General in the Excel spreadsheet. Dim csv_fileName ‘As String (tried Variant as well)’ Build the Export Filecsv_fileName = create_csv.Range(“B3”).Value & “.csv” However, if I add a string value in front, then it workscsv_fileName = “anything” & create_csv.Range(“B3”).Value & “.csv” Sub ExportToCSVFile() Dim cell As Range Dim colIndex As Long Dim colMax As Integer Dim create_csv As Worksheet Dim csv_fileName As String Dim currentUser As String Dim delimiter As String Dim extractedCount As Integer Dim line As String Dim oneDrivePath As String Dim myChoicePath As String Dim productToHelium_ws As String Dim rng As Range Dim rowIndex As Long Dim spDirectory As String Dim src_ws As Worksheet Dim stream As Object ‘ ADODB.Stream On Error GoTo ErrorHandler ‘ Set the maximum number of columns to extract colMax = 3 ‘ Set the worksheet location for the input variables Set create_csv = ThisWorkbook.Sheets(“Create_CSV”) ‘ Build the Export File csv_fileName = create_csv.Range(“B3”).Value & “.csv” ‘ Get the output Directory myChoicePath = create_csv.Range(“B7”).Value ‘ Set the name of the source worksheet that holds the data for export Set src_ws = ThisWorkbook.Sheets(“sheet2”) ‘ ‘ Define the file path for the CSV file ‘ The user must have created a shortcut link to the SharePoint location. This is explained in the create_csv worksheet. ‘ If myChoicePath = “My Choice” Then filePath = Application.GetSaveAsFilename(InitialFileName:=csv_fileName, FileFilter:=”CSV Files (*.csv), *.csv”) ‘ Check if user cancelled the Save As dialog If filePath = “False” Then Exit Sub Else ‘ assume we have a SharePoint location chosen. C18 is the SP location… Read More