I have written a VBScript to automate the creation of a Word document.
I'm using the following code to insert an image, but I can't seem to find a way to then resize it.
objSelection.InlineShapes.AddPicture("C:\test.jpg")
The AddPicture method returns a handle to the inserted object, so you could do something like this:
Set pic = objSelection.InlineShapes.AddPicture("C:\test.jpg")
pic.Height = 100
pic.Width = 200
Related
i'm using VBS to create a title screen and i have a problem trying to send a image behind te text.
Here is my code:
function page()
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set objDoc = oWord.Documents.Open("C:\xxx.docx")
objDoc.Sections.PageSetup.DifferentFirstPageHeaderFooter = true
Set head = objDoc.Shapes.AddPicture("C:\img.png")
head.PictureFormat.Brightness = 0.7
head.ZOrder msoSendBehindText 'I try to use msoSendToBack, SendBack, SendBehindText, Back and others and not work
end function
i just want send "head" to the back , the actual result is the image is not in the back of text, and the version of word is 2013.
If someone, know how to solve this, thanks in advance.
The solution was, the utilization of numeration
head.ZOrder 5
https://bettersolutions.com/vba/enumerations/msozordercmd.htm
with this change, i solve my problem.
I'm trying to compare between 2 bmp files looks the same but with Mercury.FileCompare the result return false.
i want to get the difference in precentege? any suggest?
Maybe some way to take bitmap and draw the image as array of number between 0-255?
Thanks
You can still use the old way to compare bitmaps
Set objMercuryFilecompare = CreateObject("Mercury.FileCompare")
If objMercuryFilecompare.IsEqualBin("C:\Users\pankaj.jaju\Desktop\test1.bmp" , "C:\Users\pankaj.jaju\Desktop\test2.bmp",0,1) Then
msgbox "match"
else
msgbox "mismatch"
end if
Set objMercuryFilecompare = nothing
I want to generate a barcode.png file but the file generated contains the Barcode number also and I don't want that, I only want image without Text.
How to do that?
Below is my code:-
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));`
The text will not generate in case you pass the null parameter to setFont function of Barcode class. Your code looks like as below
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setFont(null);
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));
only adding this to your code :
barcode3.setDrawingText(false);
the method above will remove text from the barcode. full code
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setDrawingText(false);
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));
I would like to evauluate the value of a textbox report control and hide or display it based on its value, which I can achieve easily with VBA:
If Me.Fixed.Value = 0 Then
Me.Fixed.Visible = False
End If
That works fine, but the query I am using as the report's record source allows a range of records to be printed all at once (1 per page/report), and I want the above code to run for each page/report. I am unsure of where to put the code so that each record will play by the rules. Currently, if I choose a range of 8 records, only the first one does what I want, and as I navigate through the other records in the print preview screen the format of the report is remaining unchanged when it should be changing.
I have tried the following events:
Report:
On Current
On Load
On Got Focus
On Open
On Activate
On Page
Section:
On Format
On Print
On Paint
Where can I put my VBA so that each time I scroll through/navigate the range of records returned on that report my code runs?
You need to set the Visible property back to True as well, otherwise it will remain invisible.
I'm using the Format event of the Details section:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Fixed = 0 Then
Me.Fixed.Visible = False
Else
Me.Fixed.Visible = True
End If
End Sub
This works in Print Preview but not in Report View. There is probably a way to get this to work with the Report View, but I never use this view.
The statement can be simplified:
Me.Fixed.Visible = Not (Me.Fixed = 0)
Note that the Visible property is not available in the Detail_Paint() event, which is the event you need to use to have the conditional formatting apply in Report View. (Which might be required if you are trying to do something fancy such as simulated hyperlinks for a drill-down effect.)
A workaround is to set the ForeColor of the text box to equal the BackColor. Although the text is technically still there, it does not "show" on the displayed report, thus simulating a hidden field.
Private Sub Detail_Paint()
' Check for even numbers
If (txtID Mod 2 = 0) Then
txtID.ForeColor = vbBlack
Else
' Set to back color to simulate hidden or transparent.
' (Assuming we are using a Normal BackStyle)
txtID.ForeColor = txtID.BackColor
End If
End Sub
Example Output:
I have a load of data in 100 .sdf files (labelled 0000.sdf to 0099.sdf), each of which contain a still image, and I'm trying to produce a .gif from these images.
The code I use to plot the figure are (in the same directory as the sdf files):
q = GetDataSDF('0000.sdf');
imagesc(q.data');
I've attempted to write a for loop that would plot the figure and then save it with the same filename as the sdf file but to no avail, using:
for a = 1:100
q=GetDataSDF('0000.sdf');
fh = imagesc(q.dist_fn.x_px.Left.data');
frm = getframe( fh );
% save as png image
saveas(fh, 'current_frame_%02d.jpg');
end
EDIT: I received the following errors when trying to run this code:
Error using hg.image/get
The name 'Units' is not an accessible property for an instance of class 'image'.
Error in getframe>Local_getRectanglesOfInterest (line 138)
if ~strcmpi(get(h, 'Units'), 'Pixels')
Error in getframe (line 56)
[offsetRect, absoluteRect, figPos, figOuterPos] = ...
Error in loop_code (line 4)
frm = getframe( fh );
How do I save these files using a for loop, and how do I then use those files to produce a movie?
The reason for the error is that you pass an image handle to getframe, but this function excpects a figure handle.
Another problem is that you always load the same file, and that you saveas will not work for gifs. (For saving figures as static images, maybe print is the better option?)
I tried to modify my own gif-writing loop so that it works with your data. I'll try to be extra explicit in the comments, since you seem to be starting out. Remember, you can always use help name_of_command to display a short Matlab help.
% Define a variable that holds the frames per second your "movie" should have
gif_fps = 24;
% Define string variable that holds the filename of your movie
video_filename = 'video.gif';
% Create figure 1, store the handle in a variable, you'll need it later
fh = figure(1);
for a = 0:99
% Prepare file name so that you loop over the data
q = GetDataSDF(['00' num2str(a,'%02d') 'sdf']);
% Plot image
imagesc(q.dist_fn.x_px.Left.data');
% Force Matlab to actually do the plot (it sometimes gets lazy in loops)
drawnow;
% Take a "screenshot" of the figure fh
frame = getframe(fh);
% Turn screenshot into image
im = frame2im(frame);
% Turn image into indexed image (the gif format needs this)
[imind,cm] = rgb2ind(im,256);
% If first loop iteration: Create the file, else append to it
if a == 0;
imwrite(imind,cm,video_filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,video_filename,'gif','WriteMode','append','DelayTime',1/gif_fps);
end
end
One more note: When the size of the data is the same for each plot, it makes sense to only use the plot(or in this case, imagesc) command once, and in later loop iterations replace it with a set(ah,'Ydata',new_y_data) (or in this case set(ah,'CData',q.dist_fn.x_px.Left.data'), where ah is a handle of the plot axes (not the plot figure!). This is orders of magnitude faster than creating a whole new plot in each loop iteration. The downside is that the scaling (here, the color-scaling) will be the same for each plot. But in every case that I have worked on so far, that was actually desirable.