Ik zit met het volgende probleem:
Ik wil in excel via een knop een bepaalde sheet opslaan.
Dit is niet zo moeilijk want dit kan met de volgende code:
Maar nu komt het probleem!
Ik wil niet heel de sheet opslaan, maar cel A1 t/m I54.
Ik heb al vanalles geprobeerd met:
range
activate
sheets.activate
copy
maar ik kom er niet uit
Ik wil in excel via een knop een bepaalde sheet opslaan.
Dit is niet zo moeilijk want dit kan met de volgende code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| Sub Opslaan_Klikken()
'Working in Excel 2000-2007
Dim fname As Variant
Dim NewWb As Workbook
Dim FileFormatValue As Long
'Check the Excel version
If Val(Application.Version) < 9 Then Exit Sub
If Val(Application.Version) < 12 Then
'Only choice in the "Save as type" dropdown is Excel files(xls)
'because the Excel version is 2000-2003
fname = Application.GetSaveAsFilename(InitialFileName:="", _
filefilter:="Excel Files (*.xls), *.xls", _
Title:="Planning")
If fname <> False Then
'Copy the ActiveSheet to new workbook
Sheets("Planning").Copy
Set NewWb = ActiveWorkbook
'We use the 2000-2003 format xlWorkbookNormal here to save as xls
NewWb.SaveAs fname, FileFormat:=-4143, CreateBackup:=False
NewWb.Close False
Set NewWb = Nothing
End If
Else
'Give the user the choice to save in 2000-2003 format or in one of the
'new formats. Use the "Save as type" dropdown to make a choice,Default =
'Excel Macro Enabled Workbook. You can add or remove formats to/from the list
fname = Application.GetSaveAsFilename(InitialFileName:="", filefilter:= _
" Excel 2000-2003 Workbook (*.xls), *.xls,", _
FilterIndex:=2, Title:="Planning")
'Find the correct FileFormat that match the choice in the "Save as type" list
If fname <> False Then
Select Case LCase(Right(fname, Len(fname) - InStrRev(fname, ".", , 1)))
Case "xls": FileFormatValue = 56
Case Else: FileFormatValue = 0
End Select
'Now we can create/Save the file with the xlFileFormat parameter
'value that match the file extension
If FileFormatValue = 0 Then
MsgBox "Sorry, unknown file extension"
Else
'Copies the ActiveSheet to new workbook
Sheets("Planning").Copy
Set NewWb = ActiveWorkbook
'Save the file in the format you choose in the "Save as type" dropdown
NewWb.SaveAs fname, FileFormat:= _
FileFormatValue, CreateBackup:=False
NewWb.Close False
Set NewWb = Nothing
End If
End If
End If
End Sub |
Maar nu komt het probleem!
Ik wil niet heel de sheet opslaan, maar cel A1 t/m I54.
Ik heb al vanalles geprobeerd met:
range
activate
sheets.activate
copy
maar ik kom er niet uit