PDA

View Full Version : How to replace specific formulas by values and then generate several xlsx/pdf filenam



Alternsti
02-12-2022, 05:02 PM
Hi everyone,

Right now I'm able to generate xlsx/pdf files based on a worksheet.

1- User must fill the worksheet 'Names"
2- User activate the macro and user must select which excel template to use to fill new xlsx files. Template have all the informatios to build several xlsx files but we only need to generate few sometime.

Once completed, every xlsx file have 2 worksheets ("DS" & "Data"). I want to replace only cell formulas using ex. "*Data*" by the cell values & then delete the "Data" worksheet. I've tried several time to figure out but I'm stuck. I think I'll need to use another macro to find&replace into specific folder.


Sub GF()

'Pick the template to copy
PT = Application.GetOpenFilename("Excel Files,*.xlsx,", , "Select the template", False)

'Get filenames for another workbook/worksheet
NFCLN = "GF_WIP.xlsm"
Workbooks(NFCLN).Worksheets("Names").Activate
PDE = Cells(Rows.Count, 1).End(xlUp).Row

'Disable screen flickering.
Application.ScreenUpdating = False

'Loop
Dim i As Integer
For i = 2 To PDE

'Get filename
NI = Workbooks(NFCLN).Worksheets("Names").Cells(i, 1)
NF = "xxxx-xxxxx-" & NI & ".xlsx"
NI_PDF = Workbooks(NFCLN).Worksheets("Names").Cells(i, 2)

'Create the file

PD = "Z:\x\x\x\x\x\x\Excel\" & NF
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Call oFSO.CopyFile(PT, PD)

'Open the file
Workbooks.Open Filename:=PD

'Save XLSX file
'The following did not work
ActiveWorkbook.SaveAs Filename:=NomFichier, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

'Generate pdf file
PTPDF = "x:\x\x\x\x\x\x\PDF\" & "xxx-xxxxxx-" & NI_PDF & ".pdf"

Workbooks(NomFichier).Worksheets(1).ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PTPDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False

'Close Excel file
Workbooks(NF).Close

'Go for the next one
Next i

'Enable the screen.
Application.ScreenUpdating = True

MsgBox "Done"

End Sub

SamT
02-13-2022, 01:27 PM
GoogleFU (https://duckduckgo.com/?q=GetOpenFilename+Select+multi&t=ffcm&atb=v301-1&ia=web)

With GetOpenFileNames MultiSelect = true

File_count = UBound(File_Names)
Counter = 1

Do Until Counter > File_count
Active_File_Name = File_Names(Counter)

Alternsti
02-13-2022, 01:57 PM
SamT: Do you mean to put this directly after here ?


'Open the file
Workbooks.Open Filename:=PD

Alternsti
02-13-2022, 02:00 PM
In short, I want to break all links between worksheets and replace those by values instead. Once done, I'll remove the "Data" worksheet inside everyone.

jolivanes
02-13-2022, 11:41 PM
https://www.excelforum.com/excel-programming-vba-macros/1371114-how-to-replace-specific-formulas-by-values-and-then-generate-several-xlsx-pdf-filenames.html

jolivanes
02-14-2022, 12:56 PM
Questions that are cross-posted to other web forums must contain links to those posts on those forums or a comment to tell us where else the question has been asked. (A, Z*)

Most, if not all forums live by this rule.
The reason is very simple. You don't want several people spending time on the same problem. It would be a waste of valuable time.