I'm trying to use STRCONV vbPropercase to correct input in a macro that I use to copy data from one "input" worksheet to another. I have been able to assign specific variables to cells and then apply the STRCONV Propercase to the variable, but no change is made to the text in the cell when I do this. The code saves the file as a combination of the variable names, so I know that it makes the corrections there. How do I make the change appear in the cell and not just to the variable in the code?
Here is an excerpt from the code I'm using:
Dim Property As String
Dim Accnt As String
Property = Worksheets("Audit").Range("L6").Value
Property = StrConv(Property, vbProperCase)
Accnt = Worksheets("Audit").Range("L7").Value
ActiveWorkbook.saveas "D:\(username)\Documents\" & Accnt & " - " & Property & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Just flip the assignment around:
Worksheets("Audit").Range("L6").Value = Property
Related
I am coding in VBA in excel. I am trying to export an excel file as a pdf. I want the name of the pdf file to be a combination of multiple things: Words (it's a name) from cell D3 & todays date & the word 'invoice'. Right now, the file exports, but it has the name 'combined' instead of showing Name09-12-202Invoice.
How do I get the 'combined' variable to reflect the Name & date & word invoice, and then get the pdf to have that name?
The code runs, just not as I am expecting. Since the exported pdf file has the name combined, instead of the information in the 'combined variable'.
I don't know if I need to have all of the dimensions for 'combined' to be a string. But if that's the case I don't know how to turn a date into a string dimension. Am I combining the clientname, client date, and client invoice variables together into one variable 'combined' properly? And primarily, why isn't the 'combined' at the end of saveLocation, not the information in the 'combined' variable?
Thank you to anyone who helps! I am new to VBA so I appreciate it!
Sub SaveActiveSheetsAsPDF()
'Create and assign variables
Dim saveLocation As String
Dim clientname As String
Dim clientdate As Date
Dim clientinvoice As String
Dim combined As String
clientname = Range("D3")
clientdate = Date
clientinvoice = "Invoice"
combined = clientname & clientdate & clientinvoice
saveLocation = "C:\Users\jessi\Documents\Info\combined.pdf"
'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:=saveLocation
End Sub
Like this:
clientname = Range("D3").Value
clientdate = Format(Date, "yyyy-mm-dd") 'Make sure you don't end up with (eg) mm/dd/yyyy format...
saveLocation = "C:\Users\jessi\Documents\Info\" & _
clientname & "_" & clientdate & "_Invoice.pdf"
'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:=saveLocation
I need some help with my VBA Script.
I need to use already assign value in vlookup formula in vba script.
Currently i'm using the below code as you can see i have already assigned Value Like "Path", "Work_sheet", "Sheet_no".
Now i want to use my assign value VBA
Required VBA
Range("C9").Formula = "=VLOOKUP(A8,'& Path & Work_sheet & sheets_no &'!$A$14:$B$14,2,FALSE)"
Currently using VBA
Path ="C:\Users\Desktop\iMAGE lINK cHECKING\"
Work_sheet = "[Main Image Link.xlsm]"
sheets_no = "Sheet1"
Range("C9").Formula = "=VLOOKUP(A8,'C:\Users\Desktop\iMAGE lINK cHECKING\[Main Image Link.xlsm]Sheet1'!$A$14:$B$14,2,FALSE)"
Your quotes were mismatched and the & need to be outside of quotes so the substitution can be made.
Range("C9").Formula = "=VLOOKUP(A8,'" & Path & Work_sheet & sheets_no & "'!$A$14:$B$14,2,FALSE)"
HTH
I'm unable to use the VLOOKUP function to search a wookbook that is a variable. One that changes name by date.
So I'm new to VBA and coding in general. Having a workbook that is a variable, according to date. Doing a VLOOKUP against that seems to be an issue. By reading online, it seems it can be done as a string, but it is already a workbook.
So bear in mind i've set wkbk as a variable (I've trimmed it down for this website, the variable searches for previous dates counting backwards from current date in a workbook named dd.mm.yyyy.xlsx and that part works fine).
Dim wkbk As Workbook
ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK(RC[-9]),"" "",VLOOKUP(RC[-9],'" & wkbk & "easy_form_response_list'!C1:C12,10))"
What I expected is a lookup of the workbook and sheet - what I get is a Run-time error '438'. Object doesn't support this property or method. Any ideas?
You need a string that is the fully formed and properly punctuated address to the external workbook's
Dim wkbk As Workbook, addr as string
SET wkbk = WORKBOOKS("THE_SOURCE_WORKBOOK.XLSX")
addr = wkbk.worksheets("easy_form_response_list").Range("A:L").Address(ReferenceStyle:=xlR1C1, External:=true)
ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK(RC[-9]), text(,), VLOOKUP(RC[-9], " & addr & ", 10))"
Are you sure you don't need this?
ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK(RC[-9]), text(,), VLOOKUP(RC[-9], " & addr & ", 10, FALSE))"
If you omit the optional fourth argument, your data needs to be sorted in an ascending manner.
Ok, I will try to explain this the best I can. I have an Excel workbook that will be used as a cost sheet. At the top of this worksheet will be a Proposal Number (in cell D3), Customer Name in cell D4), and System Size (in cell D5). So let's say my sheet is Proposal Number 4423 for Customer Shanghai Noon and System Size 2500. I would like when I click Save As for it to automatically name the file "4423 Shanghai Noon SCR-2500 Tsoc". Is there a way to do this with a Macro or any other way? Any advice is greatly appreciated.
Ok so this is the code I got from recording a macro but it keeps saying Compile error: Expected: end of statement. I don't know how to make it use the text from these cells in the Save As.
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\walkerja\Documents\CU Proposals\Range("D3").Select Range("D4").Select SCR-Range("D5").Select Tsoc.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Change your code to this:
Dim part1 As String
Dim part2 as String
Dim part3 as String
part1 = Range("D3").Value
part2 = Range("D4").Value
part3 = Range("D5").Value
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\walkerja\Documents\CU Proposals\" & part1 & " " & part2 & " SCR-" & part3 & " Tsoc.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
You were mixing string values with spreadsheet operation methods. You need to get the values of your cells first, then you can use those values to build a string for the file name.
I have an .xltm template spreadsheet that I'm wondering if I can get a macro to populate the "save as" file name based on cell data, is this possible?
There are over 50 people who will have this spreadsheet, it's more of a form, and we are trying to figure out a way to keep the filenames uniform. I know there is the ThisWorkbook.BeforeSave, but I'm not really having any luck there. I just need it to make a file named something like $A$1 R $B$1 T $B$3.xlsx
Any ideas on how to do this?
Sure.
Sub SaveMyWorkbook()
Dim strPath As String
Dim strFolderPath as String
strFolderPath = "C:\"
strPath = strFolderPath & _
Sheet1.Range("A1").Value & "R" & _
Sheet1.Range("B1").Value & "T" & _
Sheet1.Range("B3").Value & ".xlsx"
ActiveWorkbook.SaveAs Filename:=strPath
End Sub
EDIT: After you clarified your question in your comment below, I can now safely say that the answer is: No, what you are asking is not possible.
What is possible is to put a big, fat command button on your sheet that says "Press me to save", and have that button call the above Sub. You can set a fixed folder, as in the example above, or have the user pick a folder using the FileDialog object (or the GetSaveAsFilename function, but then the user will be able to change the suggested filename, so less safe).