Adding and Saving Workbooks - Part 2

Excel VBA for Beginners 7- Dealing with Workbooks
10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€92.84
List Price:  €129.98
You save:  €37.14
£79.48
List Price:  £111.28
You save:  £31.79
CA$136.74
List Price:  CA$191.45
You save:  CA$54.70
A$150.88
List Price:  A$211.24
You save:  A$60.36
S$135.02
List Price:  S$189.03
You save:  S$54.01
HK$781.40
List Price:  HK$1,093.99
You save:  HK$312.59
CHF 90.57
List Price:  CHF 126.80
You save:  CHF 36.23
NOK kr1,084.75
List Price:  NOK kr1,518.70
You save:  NOK kr433.94
DKK kr692.49
List Price:  DKK kr969.51
You save:  DKK kr277.02
NZ$166.11
List Price:  NZ$232.56
You save:  NZ$66.45
د.إ367.25
List Price:  د.إ514.16
You save:  د.إ146.91
৳10,956.06
List Price:  ৳15,338.92
You save:  ৳4,382.86
₹8,347.75
List Price:  ₹11,687.19
You save:  ₹3,339.43
RM473.85
List Price:  RM663.41
You save:  RM189.56
₦123,487.65
List Price:  ₦172,887.65
You save:  ₦49,400
₨27,772.29
List Price:  ₨38,882.31
You save:  ₨11,110.02
฿3,673.43
List Price:  ฿5,142.95
You save:  ฿1,469.52
₺3,227.91
List Price:  ₺4,519.21
You save:  ₺1,291.29
B$507.22
List Price:  B$710.14
You save:  B$202.91
R1,843.50
List Price:  R2,580.97
You save:  R737.47
Лв181.60
List Price:  Лв254.25
You save:  Лв72.65
₩135,529.28
List Price:  ₩189,746.42
You save:  ₩54,217.13
₪374.14
List Price:  ₪523.82
You save:  ₪149.67
₱5,714.50
List Price:  ₱8,000.53
You save:  ₱2,286.03
¥15,376.28
List Price:  ¥21,527.41
You save:  ¥6,151.12
MX$1,692.97
List Price:  MX$2,370.23
You save:  MX$677.25
QR364.12
List Price:  QR509.78
You save:  QR145.66
P1,360.02
List Price:  P1,904.08
You save:  P544.06
KSh13,423.65
List Price:  KSh18,793.65
You save:  KSh5,370
E£4,794.44
List Price:  E£6,712.40
You save:  E£1,917.96
ብር5,730.37
List Price:  ብር8,022.75
You save:  ብር2,292.37
Kz83,526.97
List Price:  Kz116,941.11
You save:  Kz33,414.13
CLP$94,107.58
List Price:  CLP$131,754.38
You save:  CLP$37,646.80
CN¥707.87
List Price:  CN¥991.05
You save:  CN¥283.18
RD$5,800.92
List Price:  RD$8,121.52
You save:  RD$2,320.60
DA13,449.71
List Price:  DA18,830.13
You save:  DA5,380.42
FJ$224.39
List Price:  FJ$314.16
You save:  FJ$89.76
Q775.96
List Price:  Q1,086.38
You save:  Q310.41
GY$20,884.44
List Price:  GY$29,239.05
You save:  GY$8,354.61
ISK kr13,954.60
List Price:  ISK kr19,537
You save:  ISK kr5,582.40
DH1,006.90
List Price:  DH1,409.70
You save:  DH402.80
L1,768.33
List Price:  L2,475.74
You save:  L707.40
ден5,716.08
List Price:  ден8,002.75
You save:  ден2,286.66
MOP$803.50
List Price:  MOP$1,124.94
You save:  MOP$321.43
N$1,847.92
List Price:  N$2,587.16
You save:  N$739.24
C$3,674.94
List Price:  C$5,145.06
You save:  C$1,470.12
रु13,329.02
List Price:  रु18,661.17
You save:  रु5,332.14
S/372.66
List Price:  S/521.73
You save:  S/149.07
K385.89
List Price:  K540.26
You save:  K154.37
SAR375.01
List Price:  SAR525.03
You save:  SAR150.02
ZK2,692.78
List Price:  ZK3,770.01
You save:  ZK1,077.22
L461.79
List Price:  L646.53
You save:  L184.73
Kč2,323.07
List Price:  Kč3,252.39
You save:  Kč929.32
Ft36,167.88
List Price:  Ft50,636.48
You save:  Ft14,468.60
SEK kr1,082.52
List Price:  SEK kr1,515.58
You save:  SEK kr433.05
ARS$87,865.40
List Price:  ARS$123,015.07
You save:  ARS$35,149.67
Bs691.31
List Price:  Bs967.87
You save:  Bs276.55
COP$388,509.43
List Price:  COP$543,928.75
You save:  COP$155,419.31
₡51,021.71
List Price:  ₡71,432.44
You save:  ₡20,410.72
L2,466.06
List Price:  L3,452.59
You save:  L986.52
₲747,341.53
List Price:  ₲1,046,308.05
You save:  ₲298,966.51
$U3,819.97
List Price:  $U5,348.11
You save:  $U1,528.14
zł401.45
List Price:  zł562.05
You save:  zł160.59
Already have an account? Log In

Transcript

Hey guys welcome back. So in this video we're going to discuss the workbook dot Save as method. So the workbook dot Save as method allows us to save a newly created workbook to a certain location. And what we're going to do here we're going to add a new workbook and try to save it. So first of all, we're going to use this statement here workbooks, to add a new workbook or to create a new workbook. And this is similar to pressing Ctrl N on your keyboard, and then active workbook Save As to save the workbook.

So let's go through these lines of code step by step by pressing f8 on our keyboard. So now we've added a new workbook and the reason I've used active workbook here is because when you create a new workbook, it becomes the active workbook. So you can see here when we executed the first statement, workbooks that add a new workbook was added here with the name of book one. So if we execute this statement here right away and we haven't provided a location or anything, you can see that the statement one through five And actually, this workbook book one has been saved. It's been saved actually in the default location for saving workbooks, which is actually my Documents folder as well. So if you check that you can see here that book one has been saved in the Documents folder.

Of course, this is not the recommended way of doing it because it is better to provide a location and a file format. So actually, I'd recommend when use the Save as method to always specify a file name and a file format. And I'll tell you why in just a second. So actually, in the file name parameter here, you need to provide the full path for the directory or for the folder that you need to save the file in. And you need to also include the file name and its extension as well. So let's say I'm going to save it actually to the test folder on my desktop.

I'm going to call it test and it's an extension is going to be actually dot XLS M. Okay, so I've closed book one that we had saved to the Documents folder and I'm going to execute the code Again, and watch what happens now when I actually provide the file name and do not provide the file format parameter. So actually now a new book has been open here book two. So if I tried to save that, it actually does not save and it says the extension cannot be used with the selected file type change the file extension the file, name textbox, or select a different file type by changing the Save as type. So because I have not provided the file format parameter, I gotten an error. And actually sometimes and don't get an error, if actually the extension I'm saving with is the same as the default extension for Excel that I've set in the Excel settings, which you can set actually by going to File and then options and then save.

Okay, and this is actually the default extension and although the default extension is the same, it has not saved but sometimes actually saves. But this is why you You need to actually develop a habit of always using the file format parameter, as this will save you any problems. So you need to make sure to use the file format parameter all the time. And to determine the valid values for the file format parameter, you can actually go to the workbook the Save as page on MSDN on the Microsoft directory network by highlighting this active workbook, save as and pressing f1 on your keyboard or you can just google workbook Save as method MSDN. And you should be able to reach that page. So let's go to the page on the Microsoft directory network.

So I'm going to highlight that and press f1 on my keyboard. Okay, so we're now on the workbook, save as method page on the Microsoft directory network. And actually, you can see here, here's the fall format parameter. and here if you click on this link here, Excel file format, you're going to be broken To the page that contains all the file formats that you can put into that parameter. So here are all the file formats that you can put, okay, these are the Excel file formats. You can either input the name or you can input the value.

Okay? So you can either input for example, Excel add in or input 18. Okay, so one of the famous ones that you would use a lot is the macro enabled workbook, the Excel macro enabled workbook, a school Excel, Open XML workbook macro enabled, this is the one or you could also input 52. That would work as well. So I'm just going to copy that here. I'm going to head back to my Visual Basic Editor.

Okay, so I'm back on the Visual Basic Editor and I've pasted the value for the file format parameter here. And now if you're trying to run the code, I'll step through it step by step. So workbooks dot add, and then active workbook. Save as With that, this donation and with that fall format, and you can see here that the code has run fine and we've been able to save the file. So let's check our test folder on my desktop. Okay, so here's the test folder on my desktop.

And you can see here, we've been able to save the file and its type is a Microsoft Excel macro enabled worksheet. Okay, guys, so I want to explain more parameters on the Save as method. So actually, you can see here that this code is taking so long it's so horizontally, it's taking a lot of real estate. Actually, I can go to a new line and still type parameters into the Save as method by pressing a space and then an underscore and then I can press enter to go to a new line. And now I can continue typing into the Save as method in the new line. So to space and then an ns score and then you press Enter.

And now we are in a new line. But we're still typing values into the parameters for the workbook dot Save as method as you can see here. Okay guys, so now we're going to explain another parameter, which is the password parameter. And as its name implies, this parameter allows you to create a password for your workbook. So if use the password parameter here, password colon equals and then you need to write your password as string. So you need to write it between double quotes.

So say I'm going to make it VBA course is going to be my password. And this password is case sensitive. And that means that you need to stick to the same casing for the letters that you've typed the first time. So for example, VBA and the letter C need to be written in capital letters. And the rest of the doctors need to be written as small letters. Okay, so let's say I'm going to save my file with a password of VBA course and I'm going to make the file name to be password in the same location, which is my test folder.

So if I run this macro, the file will be saved in that folder with the password which is VBA course. So let's check that out. Okay, so here is my password file here. So if I open it, you can see here that it's telling me that it's password protected. And I need to type in a password. So I've typed the password and I'm able to access the file.

So this is what the password parameter does. So I'm going to close the file here. I'm going to go back to my Visual Basic Editor. Now we're going to explain another parameter which is the right rez password, which basically restricts writing to your file. So that means that no one can make changes in your file unless he types the password. So the first password parameter that we've just explained here, this denies any access to your file except if you type the password but this one, the right rez password, so writing restriction password, this is actually allows people to access the file.

Even if you don't type the password. So they there is a read only option. But if they don't type the password, they won't be able to change anything in the file. They can read its contents, but they cannot change anything. Okay, so let's say I'm gonna make the password the rights rez for example, like that, there's going to be my password, and the file name, I'm going to make it right whereas as well, and I'm actually going to remove this password parameter here. Just say I'm just going to create a writing restriction password only.

And if I run this macro, this is actually going to save my file with the name right trez and with a writing restriction password as well. So let's check that file. Okay, guys. So here is my file here. I'm going to open it and it's going to tell me that I can only open it as a read only if I don't type the posture but I if I need to have right access. So if I need to have editing, access I'd be able to edit the file and need to type this faster.

If I type it, I'm able to edit the file. And I'm able to save it as well save my, what I've edited, but let's just close it and reopen it again. Alright guys, so I've reopened it again. And if I asked for a read only access on I try to edit in the file and try to save it as it tells me that I cannot save it because the files are read only. And it actually prompts me to save another copy of it, I cannot save my changes on the same copy. So I can go to the browser and start saving as usual.

Okay, guys, so we're not going to go into the rest of the parameters because these are actually more than enough for a beginner in VBA. I'm actually going to include also a link for a blog post that actually explains the rest of the parameters, though they are not as important and you probably won't use them, especially if you're a beginner and excel vba and you're still trying to learn excel vba. So actually, these parameters that we've explained are more than enough for a beginner which is actually what this course is started at for this course is targeted for beginners. So that's it guys for the workbook. Save as method. Thank you very much for watching this video and I'll see you on the next one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.