Hi there,
Im trying to write some code that selects a range of cells, different every time, that exports it to a new file with a predifined file name except voor the weeknumber.
I first make a selection of the cells I want by filtering on weeknumber.
After that I use to following code to export it to a new file;
/code
Sub Exportplanning()
Dim strFileName As String
strFileName = "Uitvoeringsplanning BRTTI 2014 week " & InputBox("Geef de desbetreffende weken aan en geef aan of het om voorlopig gaat (v) of definitief (def) Uitvoeringsplanning BRTTI 2014 week ..", "Geef de bestandsnaam op")
If Trim(strFileName) = vbNullString Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Copy
With ActiveWorkbook.ActiveSheet
Cells.Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
.Parent.SaveAs "D:\rpreijnd\Desktop\" & strFileName & ".xlsx", xlOpenXMLWorkbook
.Parent.Close False
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
/code
The problem is that I want the new file to be without the hidden rows and colums. I can't seem to get it right.
Also I want the cells in the new file to be as value and not as formula, I tried some code, but It messed the whole file up.
The other problem is that when I hit the cancel butten it still generates a file. What is the right code to get the action to stop if i hit cancel?
Im trying to write some code that selects a range of cells, different every time, that exports it to a new file with a predifined file name except voor the weeknumber.
I first make a selection of the cells I want by filtering on weeknumber.
After that I use to following code to export it to a new file;
/code
Sub Exportplanning()
Dim strFileName As String
strFileName = "Uitvoeringsplanning BRTTI 2014 week " & InputBox("Geef de desbetreffende weken aan en geef aan of het om voorlopig gaat (v) of definitief (def) Uitvoeringsplanning BRTTI 2014 week ..", "Geef de bestandsnaam op")
If Trim(strFileName) = vbNullString Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Copy
With ActiveWorkbook.ActiveSheet
Cells.Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
.Parent.SaveAs "D:\rpreijnd\Desktop\" & strFileName & ".xlsx", xlOpenXMLWorkbook
.Parent.Close False
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
/code
The problem is that I want the new file to be without the hidden rows and colums. I can't seem to get it right.
Also I want the cells in the new file to be as value and not as formula, I tried some code, but It messed the whole file up.
The other problem is that when I hit the cancel butten it still generates a file. What is the right code to get the action to stop if i hit cancel?