Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Tuesday, March 15, 2016

Convert xls to xlsx

Sub Xls_to_Xlsx()

    Dim strCurrentFileExt   As String
    Dim strNewFileExt       As String
    Dim objFSO              As Object
    Dim objFolder           As Object
    Dim objFile             As Object
    Dim xlFile              As Workbook
    Dim strNewName          As String
    Dim strFolderPath       As String

    strCurrentFileExt = ".xls"
    strNewFileExt = ".xlsx"
    strFolderPath = "F:\Dropbox\temp\ldvl\ldvl2009\bygender"
    If Right(strFolderPath, 1) <> "\" Then
        strFolderPath = strFolderPath & "\"
    End If

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.getfolder(strFolderPath)
    For Each objFile In objFolder.Files
        strNewName = objFile.Name
        If Right(strNewName, Len(strCurrentFileExt)) = strCurrentFileExt Then
            Set xlFile = Workbooks.Open(objFile.Path, , True)
            strNewName = Replace(strNewName, strCurrentFileExt, strNewFileExt)
            Application.DisplayAlerts = False
            Select Case strNewFileExt
            Case ".xlsx"
                xlFile.SaveAs strFolderPath & strNewName, XlFileFormat.xlOpenXMLWorkbook
            Case ".xlsm"
                xlFile.SaveAs strFolderPath & strNewName, XlFileFormat.xlOpenXMLWorkbookMacroEnabled
            End Select
            xlFile.Close
            Application.DisplayAlerts = True
        End If
    Next objFile

ClearMemory:
    strCurrentFileExt = vbNullString
    strNewFileExt = vbNullString
    Set objFSO = Nothing
    Set objFolder = Nothing
    Set objFile = Nothing
    Set xlFile = Nothing
    strNewName = vbNullString
    strFolderPath = vbNullString
End Sub

Sunday, June 7, 2015

Prevent save as in Excel

The code below can be used to stop any users saving a Workbook as another name and another location.
The code must be placed in the Private Module of the Workbook Object (ThisWorkbook). The fastest way to get there is to right click on the Excel icon, top left next to File and select View Code. It is in here you should place the code below and then save the Workbook. So long as the Workbook is opened with macros enabled the code will fire anytime any user tries to use Save As.
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

 If SaveAsUI = True Then Cancel = True

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.ThisWorkbook.Saved = True 'Tells Excel that the _
file has already been saved (this prevents Excel from requesting _
that you save the file when you close it)

End Sub
  Source 
http://www.excel-pratique.com/en/vba_tricks/preventing_a_file_from_being_saved.php 
http://www.ozgrid.com/VBA/prevent-save-as.htm

Wednesday, June 3, 2015

Hide worksheet Excel

Ẩn worksheet trong excel

1. Trước khi ẩn nên Protect sheet trước
Trên thanh Ribbon
Review/ Protect Sheet/ Chọn mật khẩu

2. Ẩn worksheet bằng cửa sổ VBE
Ấn Alt + F11 hiện cửa sổ VBA
View/ Properties Window hay ấn F4
Trong cửa số Properties Window của Sheet muốn ẩn chọn Visible ở gần cuối
Chọn Veryhidden

3. Khóa VBA vào
Cũng trong cửa số VBA
Tool/ VBA Project Properties.../
                      /Proctection/
                               ---> nhập pass

Giấu công thức Excel

Chọn cells cần giấu công thức
Right mouse Click/ Format cells/Protection/ Tick Locked & Hidden

Trên thanh Ribbon
Review /Protect sheet
Đánh mật khẩu ---> Ok

Friday, May 29, 2015

Tuesday, May 19, 2015

Tăng độ chính xác của Goal Seek

File/Options/Formulas

Tick: Enable iterative calculation
Maximum Iterative: tăng lên hết cỡ
Maximum change: Giảm hết cỡ
Hoặc dùng Macro
Sub Macro1()
    With Application
        .MaxIterations = 32767
        .MaxChange = 1E-99
    End With
End Sub

Wednesday, May 13, 2015

In 1 sheet trên Excel

Sub PrintSheets()

   'Set up your variables.
   Dim iRow As Integer, iRowL As Integer, iPage As Integer
   'Find the last row that contains data.
   iRowL = Cells(Rows.Count, 1).End(xlUp).Row
   
   'Define the print area as the range containing all the data in the first two columns of the current worksheet.
   ActiveSheet.PageSetup.PrintArea = Range("A1:B" & iRowL).Address
   
   'Select all the rows containing data.
   Rows(iRowL).Select
   
   'display the automatic page breaks
   ActiveSheet.DisplayAutomaticPageBreaks = True
   Range("B1").Value = "Page 1"
   
   'After each page break, go to the next cell in column B and write out the page number.
   For iPage = 1 To ActiveSheet.HPageBreaks.Count
      ActiveSheet.HPageBreaks(iPage) _
         .Location.Offset(0, 1).Value = "Page " & iPage + 1
   Next iPage
   
   'Show the print preview, and afterwards remove the page numbers from column B.
   ActiveSheet.PrintPreview
   Columns("B").ClearContents
   Range("A1").Select
End Sub
Nguồn

Friday, July 4, 2014

Crack Microsoft Excel Password Free | Excel 2007, 2010, 2013

Nguồn

It is always annoying when forgetting passwords. It is also annoying when you inherit a document from a previous employee and it is protected by a password only they knew. But your boss asked for you to get the data from that spreadsheet and change some things and Right now! What are you going to do?

Well the good news is that if the document isn’t encrypted, this process is pretty straightforward. You will be up and running in no time! AND you don’t have to spend $40 on some software you will use only once.

If you need to crack a Word Document as well, check out my Crack Microsoft Word Password Free post.
Crack Microsoft Excel Password Instructions

These instructions cover the process of breaking edit/read only protection on Microsoft Excel workbooks and worksheets. This WILL NOT work on Excel files that have been encrypted.

Disclaimer:
There can be a number of reasons for breaking password protection on an Excel file. Before we start, please note that I take zero responsibility for the results of these instructions. You are the master of your own actions and by proceeding, you take full responsibility of your own actions.
Step 1: Make a Backup of Your File

You will be making changes to the internal structure of your document. It is good practice to create backups before starting.
Step 2: Check your file format
This will only work on Excel files that are 2007, 2010, 2013 and have “.xlsx, .xlsm” formats. If your document is in an older format “.xls” from Excel 2003 or older, open in Excel 2007, 2010, or 2013 and save as an “.xlsx file”. If your excel file has macros, save as an “.xlsm” file to enable macros.
Step 3: Disassemble your Document

Because the .xlsx file format is based on a tree structure with XML files, it is easy to disassemble. For this example, I protected both the individual worksheet and workbook on my sample excel file. We will break this protection by changing some settings in the file.

For the disassembly process, the main file compression utility in windows will work just fine. For the first part of this demo, I am using WinRAR (Free to download). If you can’t install WinRAR, please scroll down to see the alternate disassembly process using the Windows built-in file compression tool.

Disassembly with WinRAR:
  1. Open WinRAR and click the File menu.
  2. Select Open archive.
  3. Set the file type at the bottom from “all archives” to “all files”.
  4. Locate your Excel file and click “Open”
  5. Step 4: Remove Password Protection

The root view of the excel file structure:The files you are going to edit are in the xl folder that is circled in red.

For Workbook(whole excel file) Settings:
xl>workbook.xml

For Individual Worksheet File Settings:
xl>worksheets>sheet1.xml [sheet2.xml] – etc…
Make your Changes

Browse to xl>workbook.xml and double click on the file. If you are prompted to select an application, always select NOTEPAD – NOT WORDPAD!

If you are unfamiliar with XML, this might look strange. Find the line that looks like:
1
2
3
4
5
6
<workbookProtection 
workbookAlgorithmName="SHA-512" 
workbookHashValue="/PqWjbsJjvF9ZfuAX/9rSOHijK4Q==" 
workbookSaltValue="BNztIxbaEJpw7IvcclH28g==" 
workbookSpinCount="100000" 
lockStructure="1"/>
Change lockStructure=”1″ to lockStructure=”0″
Save and Close the XML file you just edited

WinRAR will tell you that “workbook.xml” was modified and ask you to update it in the archive. Select YES.Browse to xl>worksheets>sheet1.xml(or sheet2, sheet3, etc…) and double click on the file.

Delete the whole line that looks like:
1
2
3
4
5
6
7
<sheetProtection algorithmName="SHA-512" 
hashValue="p10u4BneUg3eT/wBlxTIvojOqTuf18kg==" 
saltValue="pOCHLgXP+8NSbHK89LmgGQ==" 
spinCount="100000" 
sheet="1" 
objects="1" 
scenarios="1"/>
Save and Close the XML file you just edited

When prompted to update the archive with the file you just modified, select YES.

Close out of WinRAR and Open your file.

NOTE: If you are using Excel 2010, the following buttons may need to be clicked on to “unstick” them:

Once unstuck, you should now be able to edit the document as you please.

Alternate Disassembly Instructions – Windows Archive Tool

By default, file extensions are hidden for common document types. You will need to change your folder settings to show file extensions.

Here are some instructions that should cover Windows XP, Vista and Windows 7:

http://windows.microsoft.com/en-us/windows/show-hide-file-name-extensions#show-hide-file-name-extensions=windows-vista

Once you can see the file extension of your Excel Document file, change the file extension from .xlsx, .xlsm to .zip – after the change, you will get a warning that you are changing the extension. Click OK or YES to accept.

Now that your file is in a .zip format, right-click on your file and select Open With>Windows Explorer

Click “Extract all Files”, select your file destination and click “Extract”
Remove Excel File Password Protection

Refer to Step 4 above for changes
Make your changes, save your files and move to the next step
Alternate Instructions for Reassembly
  1. Select all your files (_rels,docProps,xl,[Content_Types].xml, etc…), right-click and select: Send to>Compressed (zipped) folder. If you create your archive by selecting your main folder and not all of the files, you may run into errors when re-opening.
  2. Change the file extension of your archive back to the original – .xlsx, .xlsm. When prompted to confirm changing the file extension, select yes.
  3. You should be able to open your fixed excel file. NOTE: your new filename will be whatever file you right-clicked on to create the archive. Feel free to change it back.

unhide sheet ấn trong excel


Trong Excel không có tính năng Unhide tất cả những Sheet đang đặt ẩn , nhưng bạn vẫn muốn làm thế nào để thực hiện được việc này ?

Cách thức như sau

Mở file Excel đang có nhiều Sheet đang đặt ẩn mà bạn muốn Unhide cùng một lúc .

Bấm tổ hợp Alt-F11 để mở cửa sổ Microsoft Visual Basic .

Bấm menu Insert > Module , bạn copy nội dung bên dưới
Sub UnhideAllSheets()
Dim wsSheet As Worksheet
For Each wsSheet In ActiveWorkbook.Worksheets
wsSheet.Visible = xlSheetVisible
Next wsSheet
End Sub
Quay trở lại Excel và chạy macro có tên gọi UnhideAllSheets

Tuy nhiên vì một lí do nào đó bạn muốn Unhide từng Sheet bạn cần chọn thì sử dụng đoạn mã bên dưới
Sub UnhideSomeSheets()
Dim sSheetName As String
Dim sMessage As String
Dim Msgres As VbMsgBoxResult
For Each wsSheet In ActiveWorkbook.Worksheets
If wsSheet.Visible = xlSheetHidden Then
sSheetName = wsSheet.Name
sMessage = "Ban co muon Unhide sheet nay khong ?" _
& vbNewLine & sSheetName
Msgres = MsgBox(sMessage, vbYesNo)
If Msgres = vbYes Then wsSheet.Visible = xlSheetVisible
End If
Next wsSheet
End Sub

Thursday, July 3, 2014

Cách phá Pass Protect sheet trong Excel



Yêu cầu hệ thống:
  1. Có MS Office
  2. Có cài VBA, nếu bạn không biết nó là gì, hãy thử mở excel, xong ấn Alt+F11, nếu nó mở ra cửa sổ Microsoft Visual Basic tức đã cài VBA, nếu nó không ra thì hãy chạy lại bộ cài MS Office, chọn update, xong tìm trong nhóm cuối cùng của các gói cài đặt sẽ thấy nó.Sau khi đã chuẩn bị đầy đủ đồ chơi, tiếp theo thực hiện các bước sau:
  3. Mở file excel cần mở khoá lên
  4. Ấn Alt+F11 để mở VBA
  5. Ấn F7 để mở cửa sổ soạn thảo mã nguồn
  6. Dán đoạn code bên dưới vào cửa sổ vừa mở ra đó
  7. Ấn F5, hoặc vào menu Run\Run Sub/User form để chạy đoạn mã này
  8. Nếu ấn F5 mà nó yêu cầu lựa chọn Macroname thì chọn SheetXXX.unprotectedAll rồi click Run nó sẽ chạy
  9. Chờ từ một đến vài phút (tuỳ tốc độ CPU từng máy tính) sẽ có thông báo sheet đã được unprotect. Mỗi khi một sheet được unprotected thành công, bạn sẽ nhận được thông báo, nhớ nhấn Ok để nó unprotect sheet tiếp theo nhé. Nếu không muốn nhận được thông báo này, bạn chỉ cần xoá 3 dòng mã từ dòng 50 đến dòng 54 là xong.
Sub unprotectedAll() Dim i As Integer
For i = 1 To Application.Sheets.Count PasswordBreaker Application.Sheets(i) Next
End Sub
Sub PasswordBreaker(MySheet)
Dim pass As String
If MySheet.ProtectContents = False Then
MsgBox "Sheet '" & MySheet.Name & "' is unprotected!", vbInformation
Else
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer


On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
pass = Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)


MySheet.Unprotect pass
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
If MySheet.ProtectContents = False Then
MsgBox "Sheet '" & MySheet.Name & "' is unprotected!", vbInformation
End If
End If
End Sub

Tuesday, April 9, 2013

Bài toán tìm giao điểm của đường cung và đường cầu bằng Goal Seek



a. Giới thiệu bài toán:
Cho phương trình đường cung và đường cầu như sau:
• Đường cung: 3P - 2Q = 6 (pt 8.1)
• Đường cầu: P + Q = 30 (pt 8.2)
Từ phương trình đường cung và đường cầu ta lập được bảng 8.3 (xem hình), trong
đó giá trị cột B được gõ vào bằng tay, giá trị cột C và D được tính toán bằng công
thức (vd: ô C3 = 2/3*B3 + 2; ô D3 = 30 - B3)
Bảng số liệu

b. Công cụ để giải bài toán trên Excel:

GOAL SEEK
Thao tác:
B1. Nhấp chuột vào ô E3, chọn làm hiệu của giá cung và giá cầu.
B2. Thực hiện phép tính hiệu cho ô E3 (=C3 - D3).
B3. Nhấp phím Enter, để Excel thực hiện phép tính.
B4. Nhấp chuột trở lại ô E3
B5. Nhấp chuột vào chữ Tools trên thanh Menu.
B6. Nhấp chuột vào chữ Goal Seek…..Khi đó một cửa sổ sẽ hiện ra như sau:

B7. Đánh vào số 0 ở khung To Value rồi đánh phím Tab cho chuột nhảy sang
khung By changing cell:
B8. Nhấp chuột vào ô B3, chọn làm biến thay đổi.
B9. Nhấp chuột vào nút OK, khi đó Excel sẽ cho giá trị ô B3 thay đổi cho đến
khi ô E3 bằng 0, nghĩa là giá cung và giá cầu bằng nhau.
B10. Nhấp chuột vào nút OK để kết thúc bài toán.





Tuesday, March 26, 2013

Hàm tách tên trong excel


Private Function Tachten(ten As String, lg As Integer)
Dim j As Integer
Name = Trim(ten)
For j = Len(Name) To 1 Step -1
If Mid(Name, j, 1) = " " Then
If lg = "1" Then
Tachten = Right(Name, Len(Name) - j)
Else
Tachten = Left(Name, j)
End If
Exit For
End If
Next
End Function

Thursday, September 15, 2011

addin trên Excel dùng C++

1. Excel add-in development in C/C++ Application in Finance, tác giả Steve Dalton. Kích để tải
2. Financial applications using Excel add-in development in C/C++, tác giả Steve Dalton, Second Edition. Kích để tải
Hai quyển cơ bản cùng nội dung (chưa đọc hết), nhưng quyển 2 được ghi là Now covers Excel 2007

Tham khảo tại

Friday, August 19, 2011

Check Spell or grammar when writing in MS word


Bất cứ khi nào bạn đánh văn bản nên để chế độ check Spelling and Grammar in MS Word
Khi bạn thấy có gạch chân đỏ hay xanh ở trong văn bản của mình, bạn click chuột phải vào như hình bên, nó sẽ hiện ra một số từ để bạn lựa chọn sao cho đúng
Chọn từ đúng -> ok
Đây là một hình thức kiểm tra chính tả khi viết văn bản rất hiệu quả, có thể rất tốt cho người mới học tiếng anh

Monday, August 1, 2011

Lấy dữ liệu từ web( tỷ giá, giá vàng) chỉ cần 1 lần kích chuột

My software

Trước đây mọi việc mình đều làm bằng tay mò mẫm theo từng trang web để có được dữ liệu cần thiết.
NOW
Chỉ cần nhập ngày tháng, thời gian, theo chỉ dẫn rất đơn giản để lấy được dư liệu cần thiết. Tất cả được viết bằng 1 macro trên excel
Tỷ giá chính thức theo Vietcombank
Giá vàng SJC
Thêm 1 cái về giá trị vốn hóa (gọi là thêm thôi nhưng cực kỳ cần thiết)

An introduction to VBA in Excel

This ebook is totally suitable for anyone who starts studying VBA(Visual Basic for Applications) in Excel.
Link here

Thursday, June 30, 2011

import multi xml file into excel

On Excel 2007 or farther. From Ribon bar choose Developer
Stage 1: import 1 file xml






Import\Properties
- In case too too many files choose like below (with lower accuracy) and not choose first file again


- In case to increase the accuracy


You can choose the first file again
Ok
Stage 2: Choose all files

Press Import
Wait for result